Math & Sciencemhchem | Retain chemical State Symbol

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
ghostanime2001
Posts: 402
Joined: Fri May 20, 2011 9:41 am

mhchem | Retain chemical State Symbol

Post by ghostanime2001 »

How to retain the formatting of the gaseous symbol from normal water style to cancel water style ? I just want to show the cancellation of the water compound except the physical state.

MWE:

Code: Select all

\documentclass{article} 
\usepackage{cancel}
\usepackage[version=3]{mhchem}
\begin{document}
\noindent Normal water style: \ce{H2O_{(g)}} \\
Cancel water style: \ce{\cancel{\ce{H2O}}_{(g)}}
\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

mhchem | Retain chemical State Symbol

Post by Stefan Kottwitz »

You could add a \ce for the subscript

Code: Select all

\ce{\cancel{\ce{H2O}}_\ce{(g)}}
Stefan
LaTeX.org admin
ghostanime2001
Posts: 402
Joined: Fri May 20, 2011 9:41 am

Re: mhchem | Retain chemical State Symbol

Post by ghostanime2001 »

The depth of the subscript changes is there a way to have it remain absolutely unchanged?
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

mhchem | Retain chemical State Symbol

Post by cgnieder »

mhchem usually requires a space after a command to return to upright font. Including chemmacros' possibilities this gives you several solutions:

Code: Select all

\documentclass{article}

\usepackage{cancel}
\usepackage[method=mhchem]{chemmacros}

\begin{document}

\noindent Normal water style: \ce{H2O_{(g)}} \\
cancelled wrong: \ce{\cancel{\ce{H2O}}_{(g)}} \\
cancelled with \verb=\ce=: \ce{\cancel{\ce{H2O}}_\ce{(g)}} \\ % Stefan's suggestion
cancelled with space: \ce{\cancel{\ce{H2O}} _{(g)}}

Or the chemmacros solution:\chemsetup[phases]{pos=sub}
% setup needed with most recent version of chemmacros (v3.0d)

\noindent Normal water style: \ce{H2O\gas} \\
Cancel water style: \ce{\cancel{\ce{H2O}}\gas}

\end{document}
retain_state.png
retain_state.png (22.87 KiB) Viewed 4568 times
Regards
site moderator & package author
Post Reply