1

MWE

% arara: pdflatex
\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{listings}
\begin{document}
\begin{tcblisting}{listing options={language=ruby}}
"hello #{world}"
\end{tcblisting}
\end{document}

The code above will crash on # with the familiar error (as if you had used it in normal body text). (In reality, I'm using minted for TypeScript highlighting on `hello ${world}` – the error is similar.) Escaping the character lets the code compile, but the full escape sequence makes it into the output (funnily enough).


Error texts for search engine indexing:

This error happens when you include #:

ERROR: You can't use `macro parameter character #' in horizontal mode.

--- TeX said ---
l.1 "hello #
            {world}"
--- HELP ---
The special character # has appeared in ordinary text. You probably
meant to type \#.

This error happens when you include $:

ERROR: Missing $ inserted.

--- TeX said ---
<inserted text> 
                $
l.8 \end{tcblisting}

--- HELP ---
TeX probably found a command that can be used only in math mode when
it wasn't in math mode.  Remember that unless stated otherwise, all
all the commands of Section 3.3 in LaTeX Book (Lamport) can be used
only in math mode. TeX is not in math mode when it begins processing
the argument of a box-making command, even if that command is inside a
math environment. This error also occurs if TeX encounters a blank
line when it is in math mode.
3

You are missing listing only. Otherwise, it would try to typeset the content (evaluate it as TeX in the lower part).

% arara: pdflatex: { shell: yes }
\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{listings}
\begin{document}
\begin{tcblisting}{listing only, listing options={language=ruby}}
"hello #{world}"
\end{tcblisting}
\end{document}
  • hot diggity-dog! Thanks :-) I'll accept this as the answer when the system allows me. In the meantime, I'll paste in the standard errors (for $ and #) to make the Q more searchable. – Sean Allred Sep 27 '18 at 11:48
  • @SeanAllred A good idea. tcblisting was intended to typeset TeX example when it has been created, so listing only would not have made any sense as default :) – TeXnician Sep 27 '18 at 11:49
  • The way the manual is written, that's certainly reasonable (though admittedly not how I would've done it). It's an ideal environment for that purpose. – Sean Allred Sep 27 '18 at 11:56

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.