Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

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

share|improve this answer
    
With addition of [russian]Babel it works, thank you very much! –  Artem Pelenitsyn Jun 12 at 10:24

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

share|improve this answer
    
Actually, I prefer pdflatex, so I stick with @egreg answer, but your approach also does work, thank you! –  Artem Pelenitsyn Jun 12 at 10:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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