Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

This question already has an answer here:

I seem to be unable to write a tilde in a \lstinline in a footnote. If you uncomment the only commented line in my minimal working example, you'll see what I mean:

\documentclass{article}

\usepackage{listings}

\begin{document}
This works:
\begin{lstlisting}
~/path/to/file
\end{lstlisting}

And this works: \lstinline{~/path/to/file}

And this works:\footnote{\lstinline{/path/to/file}}

%But this does \emph{not} work:\footnote{\lstinline{~/path/to/file}}
\end{document}

edit: I'm not sure if the answer to this was quite covered in the linked post (listings in footnotes) because that question related to the listings environment, not the lstinline macro.

share|improve this question

marked as duplicate by Jubobs, Malipivo, ChrisS, Adam Liter, Guido May 7 at 23:34

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.

    
I voted to keep it closed as duplicate as the method suggested by Bruno works like a charm. –  Claudio Fiandrino May 8 at 7:26

1 Answer 1

up vote 6 down vote accepted

When \lstinline is in the argument to another command it works in a limited way, because it can't perform certain activities. You can try with \scantokens, which works, at least with ~.

\documentclass{article}

\usepackage{listings}

\begin{document}
This works:
\begin{lstlisting}
~/path/to/file
\end{lstlisting}

And this works: \lstinline{~/path/to/file}

And this works:\footnote{A path: \lstinline{/path/to/file}}

But this does \emph{not} work:\footnote{A path: \scantokens{\lstinline{~/path/to/file}\relax}}
\end{document}

enter image description here

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.