On 2025/3/3 16:38, Denis Bitouzé wrote:
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.
Thanks for your reply.
I may not have been clear enough in the previous post. What I want is
not to add a label to a specific line and then reference it, which seems
to be what your reply was addressing. Instead, I am looking for a
numbering system similar to the one used in the equation environment,
where the equation number is printed to the left or right of the
formula. For my question, I want the first line of this block of code to
print a label on the left side, specifically (%o1).
Thank you again for your reply.
Best wishes,
Jinsong
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)