Optionally enable escaping to LaTeX anywhere with the LaTeX formatter

Anonymous avatarAnonymous created an issue

Most of the documents I write in LaTeX are related to my classes (lecture notes, exercises, exams, projects). Frequently I need to include pretty printed source code in them.

Sometimes I want LaTeX to format snippets of the source code. For instance, when I want to write a general name for something, like the condition and the two alternatives in a conditional command:

   if (e) c_1 else c_2

In this example I would let LaTeX typeset e, c_1 and c_2 in math mode. The reader would have a clue that they are placeholder where they would write an expression and two commands. The remaining of the source code should be highlited normally.

This feature is present in tools like the listings package for LaTeX. But for some reasons I want to use pygments, which misses the feature.

So I propose the following new option to pygments, related to the LaTeX formatter:

   If set to a string of length 2, enables escaping to LaTeX. Text
   delimited by these 2 characters is read as LaTeX code and
   typeset accordingly. It has no effect in string literals. It has
   no effect in comments if `texcomments` or `mathescape` is
   set. (default: ``''``).  *New in Pygments 1.3.2*

Reported by romildo

Comments (8)

  1. Anonymous

    The attached patch is an implementation of the feature. It would be very nice if it is accepted for inclusion in the project.

  2. Anonymous

    The attached hello.pdf file was obtained with the commands:

    $ pygmentize -o hello.tex -f latex -O full=true,escapeinside=
    | hello.c

    $ pdflatex hello

  3. Anonymous

    I'd also really appreciate this. I am having issues with the LaTeX formatter not having the correct glyphs, and being able to escape into Math mode would let me construct them manually.

  4. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.