4

I want to show a JSON object in my document. If I do the following, it works:

\begin{lstlisting}
{
  "id": "5",
  "key": "discardedCard"
}
\end{lstlisting}

But if I extend the code to the following, then there are only errors when compiling the document:

\begin{lstlisting}
{
  "id": "5",
  "key": "discardedCard",
  "value": {
    "suit": "DIAMONDS",
    "rank": "QUEEN"
  }
}
\end{lstlisting}

Error log:

! Incomplete \iffalse; all text was ignored after line 19.
<inserted text> 
                \fi 
l.19     "
          suit": "DIAMONDS",
A forbidden control sequence occurred in skipped text.
This kind of error happens when you say `\if...' and forget
the matching `\fi'. I've inserted a `\fi'; this might work.

! Incomplete \iffalse; all text was ignored after line 19.

I'd like to provide a MWE but if I run the code in a MWE then it works. So it looks like there are other parts in my bachelor thesis which break the document.

Is there a way to output code in a listing in a secure way or maybe escaped?

7
  • Please add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. Mar 3, 2013 at 15:13
  • 1
    I would guess you have a language shorthand (babel?) that defines " to do something, you can locally turn shorthands off, which might help. Mar 3, 2013 at 15:13
  • @DavidCarlisle: I thought this is related to france. Benny lives in Germany ;-) Mar 3, 2013 at 15:17
  • Thank you David! Yes, I use babel. The problem was that the name of my chapter was "\chapter{Implementation of "`Jiga"'}". I changed it to "\chapter{Implementation of Jiga}" which removed the error.
    – Benny Code
    Mar 3, 2013 at 15:19
  • There is no relation to babel. :-) Mar 3, 2013 at 15:22

1 Answer 1

7

I would guess you have a language shorthand (babel?) that defines " to do something, you can locally turn shorthands off, which might help

2
  • 3
    I had the same problem and it was related to the place of \usepackage[francais]{babel}. Solved the problem when I put it before \usepackage{listings} in preamble.
    – Penbeuz
    Dec 16, 2013 at 9:21
  • @Penbeuz That's it! Exactly the same problem (babel francais). Merci! Apr 19, 2015 at 23:34

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.