Math & ScienceCross-referencing with mhchem package

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
Sonntag
Posts: 13
Joined: Sun May 24, 2015 3:37 pm

Cross-referencing with mhchem package

Post by Sonntag »

Hi!

Code: Select all

\reaction{H2 + OH* <=> H2O + H*} 
I want to cross-reference an equation that I've introduced with the reaction-environment from the mhchem package. How can I do it? Hope for your answers. :)

Sonntag

Recommended reading 2024:

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

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

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Cross-referencing with mhchem package

Post by Johannes_B »

Hi and welcome,

undefined control sequence reaction. Please give us more information.

Code: Select all

\documentclass{article}
\usepackage[version=3]{mhchem}
\begin{document}
\reaction{H2 + OH* <=> H2O + H*} \label{Water}

See reaction~\ref{Water}
\end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Sonntag
Posts: 13
Joined: Sun May 24, 2015 3:37 pm

Cross-referencing with mhchem package

Post by Sonntag »

Here is a short mini-example:

Code: Select all

\documentclass{article}

\usepackage { chemexec }
\usepackage[version=4,arrows=pgf-filled]{mhchem}	

\begin{document}
\reaction{O2 + H* <=> OH* + O*} 
\end{document}
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Cross-referencing with mhchem package

Post by Johannes_B »

Hm, interesting. I just poked the author to have a look at this. Clemens is a very active developer, maintining multiple packages like exsheets for exam sheets and chemmacros for a whole bundle of chemistry stuff, more customizable than mhchem.

As it stands now, the package is from 2011, but not declared obsolete. Currently, your code is giving an option clash, that should be fixed within chemexec. I recommend to use the above mentioned and more up-to-date packages.

Code: Select all

\documentclass{article}
\usepackage { chemexec }
\usepackage[version=4,arrows=pgf-filled]{mhchem}
\begin{document}
\reaction{H2 + OH* <=> H2O + H* \label{Water}}
See reaction~\ref{Water}
\end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Sonntag
Posts: 13
Joined: Sun May 24, 2015 3:37 pm

Re: Cross-referencing with mhchem package

Post by Sonntag »

Thanks for your answer! :)
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Cross-referencing with mhchem package

Post by Johannes_B »

This might be an interesting read, thanks Clemens for sending me that link.
myChemistry
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Cross-referencing with mhchem package

Post by cgnieder »

chemexec has been my first attempt of writing a package ever. I knew little to nothing about writing a package and it is an obsolete package. Don't use it but use mhchem or chemmacros or chemformula instead. Using chemexec is at your own risk and I won't provide any support to any conflicts due to its usage.

Best regards
site moderator & package author
Sonntag
Posts: 13
Joined: Sun May 24, 2015 3:37 pm

Re: Cross-referencing with mhchem package

Post by Sonntag »

Thank your help!

In the other packages I couldn't find a command that numbers my reaction equations independantly from the math mode like chemexec does with the \reaction command. (It numbers reaction equations with "R1", "R2" etc.) There's a possibility to do this with the other packages that I haven't seen yet?

Sonntag
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Cross-referencing with mhchem package

Post by Johannes_B »

Sure, an up to date version needed.

Code: Select all

\documentclass{article}
\usepackage{chemmacros}
\usepackage{showframe}
\begin{document}
\listofreactions
\begin{reaction}
	H2 + O* <=> OH* + H*
\end{reaction}
\renewtagform{reaction}[R ]{\{}{\}}
\begin{reactions}
	Ca + O &-> CaO \\
	H2 + O* &<=> OH* + H*
\end{reactions}
\end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Post Reply