6

I'd like to use T2A fontshape inside verbments listings (for comments in source code), but have no luck in this. For the code

\begin{pyglist}[language=haskell]
fact n = foldl 1 (*) [1..n] -- так определяет !n профессор информатики
\end{pyglist}

result with pdflatex is

enter image description here

result with xelatex is

enter image description here

Any suggestions how to get plain T2A text in comments?

2

If pdflatex is used, you need to neutralize the active catcode of characters in with the high bit set:

\documentclass{article}
\usepackage[T2A]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{verbments}
\usepackage{etoolbox}

\makeatletter
\newcommand{\xpyg@neutralize}{% make characters in the range 128-255 printable
  \@tempcnta=128
  \loop
    \catcode\@tempcnta=12
    \ifnum\@tempcnta<255
    \advance\@tempcnta\@ne
  \repeat
}

\patchcmd{\pyglist@}
  {\VerbatimEnvironment}
  {\VerbatimEnvironment\begingroup\xpyg@neutralize}
  {}{}
\patchcmd{\endpyglist}
  {\input}
  {\endgroup\input}
  {}{}
\makeatother

\begin{document}
\begin{pyglist}[language=haskell]
fact n = foldl 1 (*) [1..n] -- так определяет !n профессор информатики
\end{pyglist}
\end{document}

The same patch is innocuous when XeLaTeX or LuaLaTeX is used, but for these you need a monospaced font that supports Cyrillic, for instance CM Unicode.

Here's a version that runs with all three engines.

\documentclass{article}
\usepackage{ifxetex,ifluatex}
\newif\ifunicodeengine
\ifxetex\unicodeenginetrue\else\ifluatex\unicodeenginetrue\fi\fi

\ifunicodeengine
  \usepackage{fontspec}
  \setmainfont[Ligatures=TeX]{CMU Serif}
  \setsansfont[Ligatures=TeX]{CMU Sans Serif}
  \setmonofont{CMU Typewriter Text}
\else
  \usepackage[T2A]{fontenc}
  \usepackage[utf8]{inputenc}
\fi

\usepackage{verbments}
\usepackage{etoolbox}

\makeatletter
\newcommand{\xpyg@neutralize}{%
  \@tempcnta=128
  \loop
    \catcode\@tempcnta=12
    \ifnum\@tempcnta<255
    \advance\@tempcnta\@ne
  \repeat
}

\patchcmd{\pyglist@}
  {\VerbatimEnvironment}
  {\VerbatimEnvironment\begingroup\xpyg@neutralize}
  {}{}
\patchcmd{\endpyglist}
  {\input}
  {\endgroup\input}
  {}{}
\makeatother

\begin{document}
\begin{pyglist}[language=haskell]
fact n = foldl 1 (*) [1..n] -- так определяет !n профессор информатики
\end{pyglist}
\end{document}

enter image description here

1
  • With addition of [russian]Babel it works, thank you very much! – Artem Pelenitsyn Jun 12 '14 at 10:24
1

run the document with xelatex or lualatex:

\documentclass{report}
\usepackage{fontspec}
\setmainfont{DejaVu Sans}
\setmonofont[Scale=0.85]{DejaVu Sans Mono}
\usepackage{verbments}
\begin{document}

\begin{pyglist}[language=haskell]
fact n = foldl 1 (*) [1..n] -- так определяет !n профессор информатики
\end{pyglist}

\end{document}

enter image description here

1
  • Actually, I prefer pdflatex, so I stick with @egreg answer, but your approach also does work, thank you! – Artem Pelenitsyn Jun 12 '14 at 10:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.