Skip to content

danielchatfield/latex-code-environment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

LaTeX environment for source code

Listings with sane defaults

Usage

Features

Autogobble

Automatically removes indentation (looks at first line of code to determine how much whitespace to gobble).

    \begin{code}{python}
        def f():
            pass
    \end{code}

If you want to override the amount of whitespace to gobble (i.e. when the first line has more whitespace than others or when you want to preserve some whitespace) then you can do this:

    \begin{code}[gobble=4]{python}
        def f():
            pass
    \end{code}

Embedded LaTeX

You can embed LaTeX code inside the code:

\begin{code}{python}
  def f()
      pass     // §O(1)§
\end{code}

The character for escaping into LaTeX was chosen as § as Apple keyboards have a dedicated key for this and it isn't used for anything else. I appreciate that for non-osx users this may be a bit annoying. You can override it like so:

\begin{code}[escapechar=?]{python}
    def f():
        pass
\end{code}

Minor tweaks

  • Tabs are displayed as 4 spaces rather than 8
  • spaces aren't underlined

About

A better environment for source code than listings.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages