2

I have some math equations within my LaTeX file and I usually denote these with $ to enter math mode. For longer equations, I will use \begin{math} ... but for some reason this is giving me an error telling me I am missing a $.

\begin{center}
\begin{math}
\example{ \Delta G = \Delta H - T\Delta S }
\label{1st_ex}
\end{math}
\end{center}

gives me

Missing $ inserted <inserted text> $ l.302 \example {\Delta ....

Even if I insert $ it still gives me that error.

The example function is

%list of equations
\usepackage[titles]{tocloft}
\newcommand{\listexamplename}{List of Equations}
\newlistof{example}{exp}{\listexamplename}
\newcommand{\example}[1]{%
\refstepcounter{example}
\par\noindent\text{Equation \theexample. #1}
\addcontentsline{exp}{example}
{\protect\numberline{\thechapter.\theexample}#1}\par}
  • 1
    How is the \example command defined? – Ulrike Fischer Apr 11 '13 at 21:47
  • 3
    $ ... $ is just a shorthand for \begin{math} ... \end{math}. For a displayed, numbered, equation, use \begin{equation} ... \end{equation}. – Torbjørn T. Apr 11 '13 at 21:49
  • 8
    Please always post complete (small) documents that show all relevant definitions. \example is not a standard command. So we do not know how it is defined If it makes a box like \mbox then the argument of the macro is always set in text mode and you'd need nested $ to use \Delta. However math in center looks very strange markup. It should be a display math environment such as equation as Torbjørn says. – David Carlisle Apr 11 '13 at 21:53

1 Answers1

2

Based solely in the information available in your question, I'll say you have three possible ways to write the equation:

\documentclass{article}
\begin{document}

\begin{equation}
    \Delta G = \Delta H - T\Delta S 
\label{eq:1st_ex}
\end{equation}

$\Delta G = \Delta H - T\Delta S $

\[\Delta G = \Delta H - T\Delta S \]

\end{document}

Which will produce an output like this:

enter image description here

Werner
  • 603,163
Mario S. E.
  • 18,609
  • Actually, you can also use $$ (TeX-equivalent of \[/\]), \(/\) (LaTeX for $) or one of the math and displaymath environment. Mathematics environments – Elmar Peise Apr 11 '13 at 22:46
  • @ExP $$ is not supported in LaTeX – David Carlisle Apr 11 '13 at 23:10
  • @DavidCarlisle are you sure? I'm using it all the time ever since I began using LaTeX years ago. – Elmar Peise Apr 11 '13 at 23:16
  • 1
    @ExP yes as in: if you report a bug in latex using $$ it'll come to me (and others) and we'll say don't use $$. "not supported" isn't the same as "doesn't work" It mostly works most of the time. The wiki page you referenced gives some of the reasons why it shouldn't be used. fleqn doesn't work also if you use $$. – David Carlisle Apr 11 '13 at 23:25
  • @DavidCarlisle thanks a lot. I was not aware of this; I'll keep it in mind. – Elmar Peise Apr 11 '13 at 23:33
  • The reason I use center is because I want to center my equation, if I remove it and use begin equation then its no longer centered. Also I'm using toclof to create a list of equations so that numbers them for me ... so if I use \begin{equation*} it still gives me the $ error. – Carl Wright Apr 12 '13 at 08:56
  • @CarlWright, It shouldn't as long as it is as I showed in my example. That's why so many people asked a complete Minimal Working Example – Mario S. E. Apr 12 '13 at 09:02
  • The $ - $ worked perfectly so I used them. The \example function I have is to make a numbered list of equations using \toclof , I've added the code to the main post. That is now giving me an error saying undefined control sequence ' \par\noindent\text{Equation \theexample. #1}' – Carl Wright Apr 12 '13 at 09:12
  • the equation environment automatically numerates all the equations. See the picture from my answer. You can look for more information about a table of equations here: http://tex.stackexchange.com/questions/14317/list-of-equations-table-of-equations – Mario S. E. Apr 12 '13 at 09:14