Skip to content

Instantly share code, notes, and snippets.

@bgeron
Last active April 21, 2016 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bgeron/6b0fd37124ab91843fee to your computer and use it in GitHub Desktop.
Save bgeron/6b0fd37124ab91843fee to your computer and use it in GitHub Desktop.
Patching the LaTeX output of Sphinx with line highligting
% Generated by Sphinx.
\def\sphinxdocclass{report}
\documentclass[letterpaper,10pt,english]{sphinxmanual}
\usepackage[utf8]{inputenc}
\DeclareUnicodeCharacter{00A0}{\nobreakspace}
\usepackage{cmap}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{times}
\usepackage[Bjarne]{fncychap}
\usepackage{longtable}
\usepackage{sphinx}
\usepackage{multirow}
\addto\captionsenglish{\renewcommand{\figurename}{Fig. }}
\addto\captionsenglish{\renewcommand{\tablename}{Table }}
\floatname{literal-block}{Listing }
\title{p Documentation}
\date{December 20, 2015}
\release{v}
\author{a}
\newcommand{\sphinxlogo}{}
\renewcommand{\releasename}{Release}
\makeindex
\makeatletter
% (omitted some lines)
\makeatother
\renewcommand\PYGZsq{\textquotesingle}
\begin{document}
\maketitle
\tableofcontents
\phantomsection\label{index::doc}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{def} \PYG{n+nf}{some\PYGZus{}function}\PYG{p}{(}\PYG{p}{)}\PYG{p}{:}
\PYG{n}{interesting} \PYG{o}{=} \PYG{n+nb+bp}{False}
\PYG{k}{print} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{This line is highlighted.}\PYG{l+s}{\PYGZsq{}}
\PYG{k}{print} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{This one is not...}\PYG{l+s}{\PYGZsq{}}
\PYG{k}{print} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{...but this one is.}\PYG{l+s}{\PYGZsq{}}
\end{Verbatim}
\renewcommand{\indexname}{Index}
\printindex
\end{document}

Documentation

def some_function():
    interesting = False
    print 'This line is highlighted.'
    print 'This one is not...'
    print '...but this one is.'
% Generated by Sphinx.
\def\sphinxdocclass{report}
\documentclass[letterpaper,10pt,english]{sphinxmanual}
\usepackage[utf8]{inputenc}
\DeclareUnicodeCharacter{00A0}{\nobreakspace}
\usepackage{cmap}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{times}
\usepackage[Bjarne]{fncychap}
\usepackage{longtable}
\usepackage{sphinx}
\usepackage{multirow}
\addto\captionsenglish{\renewcommand{\figurename}{Fig. }}
\addto\captionsenglish{\renewcommand{\tablename}{Table }}
\floatname{literal-block}{Listing }
\title{p Documentation}
\date{December 20, 2015}
\release{v}
\author{a}
\newcommand{\sphinxlogo}{}
\renewcommand{\releasename}{Release}
\makeindex
\makeatletter
% (omitted some lines)
\makeatother
\renewcommand\PYGZsq{\textquotesingle}
\begin{document}
\maketitle
\tableofcontents
\phantomsection\label{index::doc}
\begin{Verbatim}[commandchars=\\\{\}]
\PYG{k}{def} \PYG{n+nf}{some\PYGZus{}function}\PYG{p}{(}\PYG{p}{)}\PYG{p}{:}
\PYG{n}{interesting} \PYG{o}{=} \PYG{n+nb+bp}{False}
\colorbox{yellow}{\!\! \PYG{k}{print} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{This line is highlighted.}\PYG{l+s}{\PYGZsq{}}}
\PYG{k}{print} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{This one is not...}\PYG{l+s}{\PYGZsq{}}
\colorbox{yellow}{\!\! \PYG{k}{print} \PYG{l+s}{\PYGZsq{}}\PYG{l+s}{...but this one is.}\PYG{l+s}{\PYGZsq{}}}
\end{Verbatim}
\renewcommand{\indexname}{Index}
\printindex
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment