auctex-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: reftex label support for lstlisting?


From: Arash Esbati
Subject: Re: reftex label support for lstlisting?
Date: Sun, 09 Jan 2022 20:03:05 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50

Hi Uwe,

Uwe Brauer <oub@mat.ucm.es> writes:

> The correct way that a one can have a reference to a lstlisting
> environment is by using \lstset,

Yet another correct way is to put the caption into the optional argument
of the lstlisting environment.

> but it seems that reftex does not support this.

AUCTeX has some code to parse the optional argument for a caption key
and add the label key in that since 2017 (I think).  Just do `C-c C-e
lstlisting RET caption=your caption RET' and you should be done.  This
should work with RefTeX as well if you have a recent Emacs.

> Please consider
>
> ,----
> | \documentclass{article}
> | \usepackage[numbered,framed]{matlab-prettifier}
> | \usepackage[colorlinks]{hyperref}
> |  \begin{document}
> | \section{Label works with latex}
> | 
> | 
> \lstset{style=Matlab-editor,basicstyle=\mlttfamily,escapechar=",mlshowsectionrules=true,mathescape=true,morecomment={[s]{\%\{}{\%\}}},language=Matlab,label=parallel,caption=
>  ,captionpos=b,numbers=none}

Drop the caption and label keys in \lstset.

> | \begin{lstlisting}

\begin{lstlisting}[caption=foo]

Don't select the label key here, AUCTeX does that for you.

> |     [num,den]=series(num1,den1,num2,den2)
> |     [num,den]=parallel(num1,den1,num2,den2)
> |     [num,den]=feedback(num1,den1,num2,den2)
> | \end{lstlisting}
> | The reference works  \ref{parallel}, but reftex does encounter the label
>
> | \section{Label works with reftex}
> | 
> \lstset{style=Matlab-editor,basicstyle=\mlttfamily,escapechar=",mlshowsectionrules=true,mathescape=true,morecomment={[s]{\%\{}{\%\}}},language=Matlab,label=,caption=
>  ,captionpos=b,numbers=none}
> | \begin{lstlisting}
> | \label{lstl:test-matlab:1}
> |     [num,den]=series(num1,den1,num2,den2)
> |     [num,den]=parallel(num1,den1,num2,den2)
> |     [num,den]=feedback(num1,den1,num2,den2)
> | \end{lstlisting}
> | Reftex finds the label \ref{lstl:test-matlab:1} but latex ignores it!!
> | \end{document}
> `----

Best, Arash



reply via email to

[Prev in Thread] Current Thread [Next in Thread]