2

I have updated my Latex installation to MacTex 2015 and the following latex code does not compile anymore:

\documentclass[10pt]{article}

\usepackage{listings}

\lstset{language={java},
        morekeywords={left,right}
        keywordstyle=\bfseries,
        basicstyle=\footnotesize\ttfamily
}

\def\java#1{\lstinline[language=java]{#1}}
\newcommand{\code}[1]{\java{#1}}

\begin{document}

\begin{table*}[t]\footnotesize
\centering
\def\arraystretch{1.1}
  \begin{tabular}{lll}
    A      & B     & C \\
    1      & 2     &  \code{left} and \code{right} \\
  \end{tabular}
  \caption{Summary}
  \label{table:summary}
\end{table*}

\end{document}

The error message is:

! Missing } inserted.
<inserted text> 
                }
l.24   \end
           {tabular}
? 
! Misplaced \crcr.
\endtabular ->\crcr 
                    \egroup \egroup $\egroup 
l.24   \end{tabular}

? 
! Extra }, or forgotten $.
\endtabular ->\crcr \egroup \egroup 
                                    $\egroup 
l.24   \end{tabular}

This is the output from the log file after adding \listfiles:

 *File List*
 article.cls    2014/09/29 v1.4h Standard LaTeX document class
 size10.clo    2014/09/29 v1.4h Standard LaTeX file (size option)
 listings.sty    2014/09/06 1.5e (Carsten Heinz)
 keyval.sty    2014/10/28 v1.15 key=value parser (DPC)
 lstmisc.sty    2014/09/06 1.5e (Carsten Heinz)
 listings.cfg    2014/09/06 1.5e listings configuration
 lstlang1.sty    2014/09/06 1.5e listings language file

I could compile it on mactex 2014. Also, if I change code to texttt or lstinline it will work. Can anyone help?

  • I get no error. Can you add \listfiles to the example and add the output you get in the log file (you'll find **File list**). – egreg Aug 12 '15 at 21:06
  • @egreg I updated the question with the output. – Wickoo Aug 12 '15 at 21:12
  • You have outdated versions of listings and related files: they should be dated 2015/06/04. Run TeX Live Utility, update and retry. – egreg Aug 12 '15 at 21:19
  • @egreg Thanks! that solved my problem. I actually installed MacTex 2015 on a machine without any existing latex installation, and got the same error, so it means MacTex 2015 ships outdated packages? In any case you can add your comment as an answer and I will accept it. Thanks again! – Wickoo Aug 12 '15 at 21:30
2

The listings package had an upgrade that fixed a problem related to tabular (see the change history).

Unfortunately, the fix was released after TeX Live had been frozen for producing the DVD, so one has to update the distribution using tlmgr or, with MacTeX, TeX Live Utility.

The updated version should solve the issue.


About your code, I'd use

\newcommand{\code}{\lstinline[language=java]}

without the argument, so you're free to use either

\code{whatever}

or

\code|whatever|

in case TeX special characters are needed (instead of | you can use any character not in the code to be printed, like for \verb).

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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