Re: label on the left side of minted or listings

Liste des GroupesRevenir à ct tex 
Sujet : Re: label on the left side of minted or listings
De : dbitouze (at) *nospam* wanadoo.fr (Denis Bitouzé)
Groupes : comp.text.tex
Date : 03. Mar 2025, 09:38:02
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <875xkqik5x.fsf@example.com>
References : 1
User-Agent : Gnus/5.13 (Gnus v5.13)
Hi,

Le 03/03/25 à 12h03, Jinsong Zhao a écrit :

I am typesetting code using minted or listings package. It works fine. Now I am
hoping to add a label, similar to equation label, on the left side of the code
block, looks like following. (%o1) is the label.
>
(%o1)  code here here here
       code here here
       code here
       code
>
However, I can't find a way to do this. Any hint will be appreciated.

IIUC, what you're after is a way to “escape” in LaTeX within the
listing. This can be done thanks to the `escapechar` option of listing
(I guess minted provides it as well). Here a MWE:

--8<---------------cut here---------------start------------->8---
\documentclass{article}
\usepackage{listings}
\lstset{
  basicstyle=\ttfamily,
  numbers=left,
  language=TeX,
  alsolanguage=[LaTeX]TeX,
  escapechar="
}
\begin{document}
In the following minimal file, the line~\ref{begin} begins the document and the
line~\ref{end} ends the document.
\begin{lstlisting}
\documentclass{article}
\begin{document}"\label{begin}"
Foo
\end{document}"\label{end}"
\end{lstlisting}
\end{document}
--8<---------------cut here---------------end--------------->8---

Best regards.
--
Denis

Date Sujet#  Auteur
3 Mar 25 * label on the left side of minted or listings5Jinsong Zhao
3 Mar 25 +* Re: label on the left side of minted or listings2Denis Bitouzé
3 Mar 25 i`- Re: label on the left side of minted or listings1Jinsong Zhao
3 Mar 25 `* Re: label on the left side of minted or listings2Peter Flynn
10 Mar 25  `- Re: label on the left side of minted or listings1Jinsong Zhao

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal