python-latex-highlighting icon indicating copy to clipboard operation
python-latex-highlighting copied to clipboard

Add caption and label

Open codingyourlife opened this issue 8 years ago • 7 comments

With lstlisting I can do something like this:

\begin{lstlisting}[breaklines,caption={My lstlisting Cpation},captionpos=b,label=lst:lstlistingWithCaptionAndLabel]
#my code for lstlisting that has a caption and label
\end{lstlisting}

Not with python-latex-highlighting:

\begin{python}[breaklines,caption={DESCRIPTION},captionpos=b,label=lst:LABEL]
#my python-latex-highlighting code where caption and label is ignored
\end{python}

Maybe not really a bug, maybe not even a missing feature but I guess this is the best way to contact the author...

codingyourlife avatar May 23 '17 22:05 codingyourlife

Okay just found a workaround. Maybe this helps someone else (just add empty lstlisting bellow):

\begin{python}
#my python-latex-highlighting with caption bellow because of additional lstlisting
\end{python}
\begin{lstlisting}[frame=none,caption={TEST123},captionpos=b,label=lst:TEST]
\end{lstlisting}

codingyourlife avatar May 23 '17 22:05 codingyourlife

Well, that's a legitimate request, I'll see if that is possible.

olivierverdier avatar May 24 '17 13:05 olivierverdier

+1

jasonzutty avatar Nov 17 '17 16:11 jasonzutty

not exactly a fix either, but another way of using the package:

\begin{lstlisting}[style=mypython,caption={Test}]
def test(x):
    print(x)
\end{lstlisting}

braingineer avatar Apr 07 '18 22:04 braingineer

Have you tried to put it into a figure? Is that feasible?

1kastner avatar Jun 18 '18 09:06 1kastner

I think the best option is to define the python environment in the same way the original lstlistings is defined in listings.sty.

I created a PR for this #10

haenry avatar Sep 30 '19 11:09 haenry

The python environment already offers the possibility to add an optional argument, it would just need to also use this argument to facilitate captions, labels etc

\lstnewenvironment{python}[1][]{\lstset{style=mypython,#1}}{}

samcarter avatar Dec 15 '21 10:12 samcarter

Fixed in #10

olivierverdier avatar Mar 18 '24 16:03 olivierverdier