4

I don't understand why the following document does not compile:

\documentclass[letterpaper, 11pt, onecolumn]{article}

\usepackage{lipsum}
\usepackage{listings}
\lstloadlanguages{[11]C++,[ISO]C++}

\begin{document}
\lipsum[1]
\begin{lstlisting}[language=[11]C++]
struct test
{
    int x = 0;
};
\end{lstlisting}
\lipsum[1]
\end{document}

Where is the problem?

4

[language=[11]C++] is an optional argument and [11] is another optional argument. In listings package, When using an optional argument inside another optional you need to use braces around the whole value.

\begin{lstlisting}[language={[11]C++}] ought to fix it.

If you check the listings documentation in Section 2.3 the third point in the \itemize explains it

→ ‘language=[77]Fortran’ does not work inside an optional argument. You must put braces around the value if a value with optional argument is used inside an optional argument. In the case here write ‘language={[77]Fortran}’ to select Fortran 77.

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.