1. Andrew Pinkham
  2. pygments-main

Wiki

Clone wiki

pygments-main / Single Quote Character

Single Quote Character

This is a bug fix for Issue #889. Knowledge of the issue may be useful to understanding this page.

By default, as of v1.6, Pygments escapes single quote characters, replacing them with \char`\' via the \PYZsq command (as long as commandprefix unchanged). This is not always desirable.

The new singlequote allows the user flexibility in selecting how he/she wants single quote characters handled. The option may be set to:

  • 'escape' - no changes (characters still escaped to \char`\') Default
  • 'tc'- characters escaped to \textquotesingle
  • 'scan' - characters escaped to \scantokens{'}

As noted in Issue #889, the 'tc' option requires the textcomp package, and the 'scan' option depends on etex, which is included in most TeX distributions. Furthermore, 'scan' is compatible with the upquote package, while 'tc' appears works independently.

Example Usages: (code.py may be found here)

from pygments import highlight
from pygments.lexers import PythonLexer
from pygments.formatters import LatexFormatter

lexer = PythonLexer()
formatter = LatexFormatter(full=True,
                           title='Single Quote tc Option',
                           preamble='\usepackage{textcomp}',
                           singlequote='tc',
                           )

with open('code.py','r') as inputFile:
    code = inputFile.read()

with open("test.tex","w") as outputFile:
    highlight(code, lexer, formatter, outputFile)
from pygments import highlight
from pygments.lexers import PythonLexer
from pygments.formatters import LatexFormatter

lexer = PythonLexer()
formatter = LatexFormatter(full=True,
                           title='Single Quote scan Option',
                           preamble='\usepackage{upquote}',
                           singlequote='scan',
                           )

with open('code.py','r') as inputFile:
    code = inputFile.read()

with open("test.tex","w") as outputFile:
    highlight(code, lexer, formatter, outputFile)

Updated