Math & ScienceChemical Equations

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
ElleSaf61
Posts: 4
Joined: Tue Oct 25, 2011 11:45 pm

Chemical Equations

Post by ElleSaf61 »

Hi.
I have problem with using chemical equations along with math ones. I use following in my main LaTeX file (of course I have several other packages in my preamble).

Code: Select all

\documentclass[letterpaper,11pt]{report}
\usepackage{amsmath}
\newcounter{chemequation}
\renewcommand*\thechemequation{[\arabic{chemequation}]}
\newenvironment{chemequation}{%
\stepcounter{chemequation}%
\begin{equation}}%
{\tag*{\thechemequation}%
\end{equation}}
\begin{document}
\include{chapter1}
\end{document}
And in chapter1 file I have

Code: Select all

\chapter{Chapter one}
\begin{equation}
  e^{\pi i} + 1 = 0
  \label{eq:1}
\end{equation}
\begin{chemequation}
  \text{CO}_2 + \text{C}  \longrightarrow 2\text{CO}
  \label{ch:1}
\end{chemequation}
LaTeX keeps sending me warnings. By adding any equation the number of warning increases. I do not know what should I do. Any help appreciated.
BTW, there is no problem when I add equations in the main file. The problem happens only when using \include{}.

Thanks,
Elham
Last edited by localghost on Wed Oct 26, 2011 10:47 am, edited 1 time in total.

Recommended reading 2024:

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

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

User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Chemical Equations

Post by cgnieder »

Hello ElleSaf,

I don't believe "New Members" is the right category for your question ;)
Also it would have been helpful, if you used the Code button to format your post. It improves readability.

To your question: this doesn't give me any warning:

Code: Select all

\documentclass[letterpaper,11pt]{report}
\usepackage{amsmath}
\newcounter{chemequation}
\renewcommand*\thechemequation{[\arabic{chemequation}]}
\newenvironment{chemequation}{%
\stepcounter{chemequation}%
\begin{equation}}%
{\tag*{\thechemequation}%
\end{equation}}

\begin{document}

\chapter{Chapter one}
\begin{equation}
e^{\pi i} + 1 = 0
\label{eq:1}
\end{equation}
\begin{chemequation}
\text{CO}_2 + \text{C} \longrightarrow 2\text{CO}
\label{ch:1}
\end{chemequation}

\end{document}
You should try to provide a true minimal example, which reproduces the warning.

However, I would suggest using the chemmacros package, anyway. It provides an environment reaction for chemical equations and also uses mhchem, which makes typesetting chemical formulae a lot easier.

Code: Select all

\documentclass[letterpaper,11pt]{report}
\usepackage{chemmacros}
\renewtagform{CMreaction}{[}{]}
\begin{document}

\chapter{Chapter one}
\begin{equation}
 e^{\pi i} + 1 = 0 \label{eq:1}
\end{equation}
\begin{reaction}
 CO2 + C -> 2 CO \label{ch:1}
\end{reaction}

\end{document}
site moderator & package author
ElleSaf61
Posts: 4
Joined: Tue Oct 25, 2011 11:45 pm

Chemical Equations

Post by ElleSaf61 »

Hello.

Thank you for your prompt reply. I tried chemmacros package and still have the same problem. As i mentioned in my previous post there is no problem when I put chemical equations in the base file. It comes when I use \include commond. Since I have a big document (~400 pages) I divided each part in separate *.tex files and then include them in the base file using \include{filename}. A short example of my file is as follows and the warning coming with it is: "pdftex warning (ext4): destination with the same identifier (name{equation.3.3.}) has been already used duplicate ignored"
my base file (this is the minimal example that gives you the same error):

Code: Select all

\documentclass[letterpaper,11pt]{report}
\usepackage{bpchem}  
\usepackage{pifont}   
\usepackage{tipa}
\usepackage{tabulary}
\usepackage{graphicx}
\usepackage{multirow}
\usepackage{rotating}
\usepackage{ctable}
\usepackage{booktabs}
\usepackage{rccol}
\usepackage{subfigure}
\usepackage{setspace}
\usepackage{amssymb,amsmath,amsthm,bm}
\usepackage[letterpaper, left=1.5in, right=1.5in, top=1in, bottom=1in, nohead]{geometry}
\usepackage{amsmath}
%============
\usepackage[version=3]{mhchem}
\newcounter{chemequation}
\renewcommand*\thechemequation{[\arabic{chemequation}]}
\newenvironment{chemequation}{%
\stepcounter{chemequation}%
\begin{equation}}%
{\tag*{\thechemequation}%
\end{equation}}
%=============
\usepackage{longtable} 
\usepackage{paralist} 
\usepackage{booktabs} 
\usepackage{nomencl}    
\makenomenclature      
\usepackage{caption}
\usepackage[printonlyused,withpage]{acronym}
\usepackage[maxfloats=37,morefloats=19]{morefloats}
%Zum URL ==================
\usepackage{url}
\makeatletter
\def\url@leostyle{%
  \@ifundefined{selectfont}{\def\UrlFont{\sf}}{\def\UrlFont{\small\ttfamily}}}
\makeatother
\urlstyle{leo}
\usepackage[colorlinks=true,linkcolor=blue,citecolor=blue,urlcolor=blue]{hyperref}
%% Kommando=====
\begin{document}
\pagestyle{empty}
\pagenumbering{roman}
\setcounter{page}{3}
\pagestyle{plain}
\doublespacing
\tableofcontents
\listoffigures
\listoftables
\pagestyle{plain}
\pagebreak
\pagenumbering{arabic} \setcounter{page}{1} \doublespacing
\include{section1}
\end{document}
and my *section1* file is:

Code: Select all

\chapter{Section one}
At anode:
  \begin{chemequation}
   \ce{2H2O \rightarrow O2 \uparrow +~4H^+_{(aq)}+ 4e- \qquad \qquad     E^0=-1.229V}
   \label{eq:anode}   
   \end{chemequation}
At the cathode:
    \begin{chemequation}
     \ce{4H2O + 4e^- \rightarrow 2H2\uparrow +~4OH^-_{(aq)}  \qquad   E^0=-0.828V}
      \end{chemequation}
 \begin{equation}
  J = \frac{I}{z_{iF}}
 \end{equation}
Btw, I tried to follow your advice about pressing Code button. Hopefully, I got it right. :)
Thanks again,
Elham
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Chemical Equations

Post by cgnieder »

Hi again,

You need to enclose the code with the opening and closing tag in order to display code as such...

I will look into your code, as soon as I have the time. However, your
example is not a real minimal working example yet, is it?
site moderator & package author
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Chemical Equations

Post by localghost »

ElleSaf61 wrote: Btw, I tried to follow your advice about pressing Code button. Hopefully, I got it right. :)
Thanks again,
Elham
You have to enclose the code you want to post by the |code| … |/code| tags*. This is simply done by marking the text passages you want to tag and then press the code button. The result should look like the following while composing or editing a message.
|code|
\documentclass[11pt]{article}
\usepackage[T1]{fontenc}

\begin{document}
Hello World!
\end{document}
|/code|
I corrected your post in this regard. If you want to look at its "source", press the edit button (but don't alter the post!).


* Note that the "|" symbol had to be chosen here as replacement for enclosing brackets to visualize the BBCode tags here.


Best regards and welcome to the board
Thorsten
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Chemical Equations

Post by cgnieder »

Hi,

The problem is the combination of things: 1) use of pdflatex, 2) use of hyperref and 3) the new environment using \begin{equation}...\end{equation} (as you can read here).

The solution is rather simple: change the definition of your chemequation environment into this:

Code: Select all

\newcounter{chemequation}
\renewcommand*\thechemequation{[\arabic{chemequation}]}
\newenvironment{chemequation}{%
\stepcounter{chemequation}%
\begin{equation*}}%
{\tag*{\thechemequation}%
\end{equation*}}
I'll have to thank you, since this pointed me to a bug in chemmacros, which I'll try to adress...

BTW: you don't need to use \rightarrow and uparrow, when you use mhchem. This will work just the same:

Code: Select all

\chapter{Section one}
At anode:
\begin{chemequation}
 \ce{2 H2O -> O2 ^ + 4 H^+_{\text{(aq)}} + 4e- \qquad \qquad     E^0=-1.229V}
 \label{eq:anode}   
\end{chemequation}
At the cathode:
\begin{chemequation}
 \ce{4 H2O + 4 e- -> 2 H2 ^ + 4 OH^-_{\text{(aq)}}  \qquad   E^0=-0.828V}
\end{chemequation}
site moderator & package author
ElleSaf61
Posts: 4
Joined: Tue Oct 25, 2011 11:45 pm

Re: Chemical Equations

Post by ElleSaf61 »

Hi.
Thank you so much for your help. It solved my problem. :P ;)
Best,
Elham
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Chemical Equations

Post by cgnieder »

BTW: chemmacros v2.0 now works, too:

Code: Select all

\documentclass{article}
\usepackage{chemmacros}
\usepackage{hyperref}

\begin{filecontents}{section1}
\begin{reaction}
 H2 + 1/2 O2 -> H2O
\end{reaction}
\begin{reaction}
 C + O2 <=> CO2
\end{reaction}
\end{filecontents}

\begin{document}
\renewtagform{reaction}{[}{]}
\include{section1}
\end{document}
Best
site moderator & package author
Post Reply