olivierverdier / python-latex-highlighting

LaTeX style for Python highlighting
BSD 3-Clause "New" or "Revised" License
453 stars 125 forks source link

Add caption and label #4

Closed codingyourlife closed 5 months ago

codingyourlife commented 7 years ago

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 commented 7 years ago

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}
olivierverdier commented 7 years ago

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

jasonzutty commented 6 years ago

+1

braingineer commented 6 years ago

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}
1kastner commented 6 years ago

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

haenry commented 4 years ago

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

samcarter commented 2 years ago

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}}{}
olivierverdier commented 5 months ago

Fixed in #10