0

I am using \usepackage{pythonhighlight} for python code and this creates a box around the code by default. Is there a way to remove the box?

\begin{python}
def f(x):
    return x
\end{python}
1
  • Welcome to TeX.SE .. Please post your code from \documentclass to \end{document}
    – MadyYuvi
    Commented Jun 4, 2021 at 18:40

1 Answer 1

1

Doesn't look like pythonhighlight has made it possible to add additional options to the python environment.

One option is to define a new listings type environment, and allow for style adjustments using the optional argument to the new environment, and add frame=none there. See PythonA below.

If you want to remove all frames, add frame=none to the new style, as with PythonB below.

A third option is to make a new style and use \begin{lstlisting}[style=stylename].

enter image description here

\documentclass[border=2mm]{article}
\usepackage{pythonhighlight}
\lstnewenvironment{PythonA}[1][]{\lstset{style=mypython, #1}}{}

\lstnewenvironment{PythonB}[1][]{\lstset{style=mypython, frame=none, #1}}{}

\lstdefinestyle{Py2}{
  style=mypython,
  frame=none
  }
\begin{document}
\begin{PythonA}[frame=none]
def f(x):
    return x
\end{PythonA}

\begin{PythonB}
def f(x):
    return x
\end{PythonB}

\begin{lstlisting}[style=Py2]
def f(x):
    return x
\end{lstlisting}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .