Docutils uses alltt in LaTeX for code blocks, so that this input:
::
Test_1234
becomes this output:
\begin{quote}
\begin{alltt}
Test_1234
\end{alltt}
\end{quote}
Unfortunately, this doesn't work in all cases. This:
.. sidebar:: asd
::
Test_1234
becomes this:
\DUsidebar{
\DUtitle[sidebar]{asd}
\begin{quote}
\begin{alltt}
Test_1234
\end{alltt}
\end{quote}
}
Which causes a LaTeX error because of the _ character:
./test.tex:66: Missing $ inserted.
<inserted text>
$
l.66 }
./test.tex:66: LaTeX Error: Command \end{alltt} invalid in math mode.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.66 }
./test.tex:66: Missing $ inserted.
<inserted text>
$
l.66 }
The problem is that it's not safe to use alltt in a macro argument, because it doesn't get to change the catcode of _. The solution would be either to make DUsidebar an environment instead of a macro, or to escape the contents of alltt.
Fixed in r8820.
We had the same problem with footnotes, admonitions and system messages, so the fix was easy.
Admonitions and system messages are now implemented as environments. This could be done for sidebars, too. However, only after a warning and with a backwards-compatibility setting. Maybe this is not worth the effort, as users may wish to map sidebars to a margin note command (which is possible with an environment but brings back the problems).
Fixed in Docutils 0.18. Thanks again for the report.