1

This question already has an answer here:

Here is the code that I have (I have removed parts which I think are not relevant):

\documentclass[12pt]{article}

\usepackage{listings}

% Python style for highlighting
\newcommand\pythonstyle{\lstset{frame=shadowbox,
  language=Python,
  ...
}}

% Python environment
\lstnewenvironment{python}[1][]
{
\pythonstyle
\lstset{#1}
}
{}

% Python for inline
\newcommand{\pythoninline}[1]{{\pythonstyle\lstinline!#1!}}

\begin{document}

\begin{figure}
\begin{python}
def function_name():
    ...
\end{python}
\caption{Definition of the function_name function.}
\end{figure}

\end{document}

What I would like to do is to use the command \pythoninline inside the figure caption argument. This does not work:

\caption{Definition of the \pythoninline{function_name} function.}

Any suggestions would be much appreciated.

marked as duplicate by Werner, Xavier, cmhughes, Gonzalo Medina, T. Verron Jun 21 '13 at 5:13

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.