Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I try to rebuild a fairly complicated math-table, and I'm almost satisfied with the result. The MWE actually compiles to the table I want, but with error messages. When I include the table in my real (big) document, I get the error messages too, but in that case the document doesn't compile anymore.

I spent quite some time experimenting with and checking the $, but cannot find the error, and would be grateful for any tip.

\documentclass[]{scrbook}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{latexsym}
\usepackage{amsmath}
\usepackage[listings,theorems]{tcolorbox}
\tcbset{before={\par\medskip\pagebreak[0]\noindent},after={\par\medskip}}%

\begin{document}


\newcounter{texercise}[chapter]
\begin{tcolorbox}[colback=blue!5,colframe=blue!50!black,arc=0mm,
theorem={Algebra}{texercise}{(Vereinfachter) Datentyp 'Liste'}{myMarker}]{}
\medskip


\begin{tabular}{llll}
 \textbf{algebra}  &  $list_1$  &  &  \\
 \textbf{sorts}    & \multicolumn{3}{l}{$list$, $elem$ \{$bool$ ist im folgenden immer implizit dabei\}}  \\
 \textbf{ops}      &  $empty$   &  $:$      &  $\to list$   \\
                   &  $first$   &  $:list$  &  $\to elem$   \\
                   &  $append$    &  $:list$  &  $\to list$   \\
                   &  $concat$    &  $:list \times elem$  &  $\to list$   \\
                   &  $isempty$    &  $:list \times list$  &  $\to bool$   \\
\textbf{sets}      &  $list$  & \multicolumn{2}{l}{$= \{ <a_1,\dots,a_n> \mid n \ge 0, a_i \in elem$\}}\\
\textbf{functions} & & & \\
                  &   $empty$ & \multicolumn{2}{l}{ $ = \Diamond$}\\
                  &   \multicolumn{3}{l}{
                     \begin{equation*}
                     $first(a_1 \dots a_n) =$
                       \begin{cases}
                         $a_1$ & \text{falls $n>0$} \\
                         undefiniert & \text{sonst}
                       \end{cases}
                     \end{equation*}}  \\
\textbf{end} $list_1$ & & & \\

\end{tabular}
\end{tcolorbox}
\end{document}

Here is the error message:

ERROR: Missing $ inserted.

--- TeX said ---
<inserted text> 
            $
l.36                      \end{equation*}}
                                        \\
--- HELP ---
TeX probably found a command that can be used only in math mode when
it wasn't in math mode....

And here is the result:

MWE result

share|improve this question

1 Answer 1

up vote 3 down vote accepted

There is no need for equation* in order to use the cases environment. Just use the following definition:

%... 
& \multicolumn{3}{l}{%
  $first(a_1 \dots a_n) =
    \begin{cases}
      a_1 & \text{falls $n>0$} \\
      \text{undefiniert} & \text{sonst}
    \end{cases}$} \\
%... 

enter image description here

In part, the problem was that you're using equation* and then initiating math mode using $...$. An equation* already initiates math mode, so the use of $ is not needed.

You may also wish to use \langle...\rangle instead of <...> for your list notation.

share|improve this answer
    
It took me a while to check that out, but if I follow your example exactly, both the MWE and the real document compile - thanks a lot. What caused a lot of confusion on my side was the fact, that the way you positioned the '$` resulted in a (completely) wrong fontification in my Emacs buffer, but it works. Putting more '$' in the formula restores the correct fontification, but results in LaTeX errors. –  user17106 Dec 4 '12 at 22:11
    
@user17106: Yes, some editors rely on the use of explicit math environments or switches (like $) in order to display the correct syntax highlighting. Mixing these in odd locations (like an equation* environment inside a tabular, say) causes the engine to not pick up on it properly, I guess. Perhaps advisable to submit a bug report to the editor programmers. It may be that the syntax parser has a number of exclusions in it for ad-hoc - yet completely appropriate in LaTeX terms - configurations. I don't know much about it, but have seen that in other editors. –  Werner Dec 4 '12 at 22:20
    
Including the \begin{cases} and \end{cases} inside $...$ doesn't seem right at first sight, and thus Emacs puts the whole part in math-font. But if I exclude the begin and end expressions by setting more $, there are LaTeX errors, strangely enough. But anyway, it works fine now, thanks. –  user17106 Dec 4 '12 at 22:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.