# Problems with comment package when comment contains diacritical characters

I often use comment package to include various comments to have possibility of creating output with omitting various temporarily comments

However, recently I found out that I have problems when comment contains diacritics. (I did not have these problems on my previous installation of MikTeX.)

\documentclass{article}
\usepackage[cp1250]{inputenc}
\usepackage[slovak]{babel}
\usepackage{comment}

\includecomment{mine}

\begin{document}

Normálny text.
Deliteľnosť.

\begin{mine}
Komentár.
\end{mine}

\end{document}


This file does not compile. (I use pdflatex, if that's relevant.) The first error in the log-file is:

 ! Undefined control sequence.
l.1 Koment\unhbox \voidb
@x \bgroup \let \unhbox \voidb@x \setbox \@tempboxa ...


After I change Komentár to Koment\'ar, everything works fine.

If I add \usepackage[T1]{fontenc} into preamble, the file compiles fine. (But the output looks a bit differently. This seems to be completely unrelated issue, which seems to be related to the choice of fonts according to answers to this question.)

It seems a bit strange to me that if I do not use comment (or if I use \excludecomment{mine}) then everything works without the fontenc package.

• You should have \usepackage[T1]{fontenc} anyway if your text is in Slovak. – egreg Sep 18 '15 at 12:42
• Thanks a lot both for this advice and for the answer. (I was unaware of the importance of using \usepackage[T1]{fontenc}.) – Martin Sep 18 '15 at 13:26

The comment package writes out the contents of the environment mine in an auxiliary file, but the expansion of á, as defined by cp1250 is fragile and doesn't survive writing out.

The situation changes when fontenc with the option T1, because in this case the character is written out as itself. However, the T1 encoding is not the same as cp1250, so it's not guaranteed that all characters behave well. For instance, ř won't.

Shortly, comment is not compatible with characters outside the seven bit ASCII range. Not all is lost: the package was written when \unexpanded wasn't available.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[cp1250]{inputenc}
\usepackage[slovak]{babel}
\usepackage{comment}

\let\ThisComment\WriteCommentLine

\includecomment{mine}

\begin{document}

Normálny text.
Deliteľnosť.

\begin{mine}
Komentár. ř
\end{mine}

\end{document}