0

When I attempt to compile my Beamer slides (very much trimmed-down code below), I encounter the following error:

! Improper alphabetic constant.
<to be read again> 
                   \relax 
l.1 \begin{python}

The Beamer slides code contains listings syntax highlighting customizations and is shown below. What might be going wrong?

\documentclass{article}

\usepackage{listings}
\newcommand\pythonstyle{\lstset{
       language=Python,
       otherkeywords={self,},
}}
\lstnewenvironment{python}[1][]{
    \pythonstyle
    \lstset{#1}
}{}

\begin{document}

\begin{python}
import multiprocessing
\end{python}

\end{document}
  • 1
    Thank you for posting a working example! At the same time, much of your code does not seem to be relevant to the question you're asking here. Please limit the example to only the code required for your issue to appear. You can have a look at this guide for how to prune your code for this purpose. – user36296 Nov 29 '16 at 20:43
  • Could you please try minimizing the code? – egreg Nov 29 '16 at 20:48
5

After removing the 90% or more of your code that was completely irrelevant, we are left with the following chunk that is broken:

\documentclass{article}

\usepackage{listings}
\newcommand\pythonstyle{\lstset{
       language=Python,
       otherkeywords={self,},
}}
\lstnewenvironment{python}[1][]{
    \pythonstyle
    \lstset{#1}
}{}

\begin{document}

\begin{python}
import multiprocessing
\end{python}

\end{document}

Commenting out the line otherkeywords={self,}, makes the problem go away, so a reasonable guess is that the problem is the comma after self. Sure enough deleting the comma fixes the problem.

  • @samcarter Luckily binary search is pretty fast. – Hood Chatham Nov 29 '16 at 23: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.