# \MakeShortVerb{\§} and \usepackage[utf8]{inputenc}

I have a book published more than 10 years ago. It contains the following code in its preamble:

\documentclass{article}

\usepackage[cp1251]{inputenc}
\usepackage[T1,T2A]{fontenc}
\usepackage[english,russian]{babel}

\usepackage{shortvrb}
\MakeShortVerb{\§}

\begin{document}
§\begin{i}§
\end{document}


Now I want to convert source files to unicode. However after changing cp1251 encoding to utf8

\usepackage[utf8]{inputenc}


compilation stopped with error message indicating on a problem with \MakeShortVerb{\§}:

! Missing \endcsname inserted.
<to be read again>
\protect
l.8 \MakeShortVerb{\В§}

? h
The control sequence marked <to be read again> should
not appear between \csname and \endcsname.

? h
Sorry, I already gave what help I could...
Maybe you should try asking a human?
An error might have occurred before I noticed any problems.
If all else fails, read the instructions.''

?

! Package inputenc Error: Keyboard character used is undefined
(inputenc)                in inputencoding utf8'.

See the inputenc package documentation for explanation.
Type  H <return>  for immediate help.
...

l.8 \MakeShortVerb{\В§}

? r


How to bypass this problem? Nothing to say that I still want to use § as delimiters for short verbatim text. Is shortverb package compatible with utf8 encoding?

• Did you actually change the file's encoding? Where is the B in \B... coming from?
– cfr
Mar 26, 2016 at 3:45
• @cfr: Yes, I have changed actual encoding in source files, but as you see the error occurs in the preamble of the main file. Mar 26, 2016 at 4:00
• If you posted a complete example, of course, somebody could actually test it or something.
– cfr
Mar 26, 2016 at 4:01
• However, if I had to guess, I'd say you are using a character which is really two for utf8 and that you therefore get the error because there is a second character where the \endcsname should be. The character may be encoded as a single character in cp1251 but for utf8 to work with 8-bit engines, as I understand it, some apparently single characters are really a sequence of two characters.
– cfr
Mar 26, 2016 at 4:06
• As @cfr observes, in UTF-8 § is a two-byte char so this can't work: you can only make short verbatim chars which are a single octet in pdfTeX. Mar 26, 2016 at 8:39

@egreg again too quick. But I had lunch to prepare...

\documentclass{article}

\usepackage[T1,T2A]{fontenc}
\usepackage[english,russian]{babel}

\usepackage[utf8]{inputenc}

%\usepackage{shortvrb}

\makeatletter
\DeclareUnicodeCharacter{00A7}{\IgorSVerb}
\def\IgorSVerb{\begingroup\def\IgorSVerb{\verb@egroup\endgroup}\verb^^a7}
\makeatother

\begin{document}
Hello

§\begin{i}$&^\}{"'çÂ\]%§ §\begin{i}$&^\}{"'çÂ\]%§

\selectlanguage{english}

§\begin{i}$&^\}{"'çÂ\]%§ §\begin{i}$&^\}{"'çÂ\]%§<

\end{document}


• the main limitation is that § can now not be used in a standard verbatim or another \verb.
– user4686
Mar 26, 2016 at 12:29
• there is an extra < at the end of the code sample which is a keyboard slip during copy paste.
– user4686
Mar 26, 2016 at 14:16
• This works with pdflatex but not with xelatex. Mar 26, 2016 at 15:42
• @IgorKotelnikov with xelatex don't load inputenc and just use \MakeShortVerb{\§}, it works !! and also you need fontspec not fontenc...
– user4686
Mar 26, 2016 at 16:05
• I use ifxetex package and \ifxetex ... \else ... \fi constract for almost all my documents to provide portability between pdflatex and xelatex and sililartly for lualatex. In MWE I just omit this portion of my code. Mar 26, 2016 at 18:32

The problem is that, in UTF-8, § is two byte long, but \MakeShortVerb wants only one.

The best I can offer is the following:

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[T1,T2A]{fontenc}
\usepackage[english,russian]{babel}

\begingroup\uccode~="C2 \uppercase{\endgroup
\DeclareUnicodeCharacter{00A7}{\verb~}}
\begingroup\uccode~="A7 \uppercase{\endgroup\def~}{}

\begin{document}

§\begin{i}§

§{-{\§

\end{document}


The limitation is that no character that in UTF-8 is prefixed by <C2> can appear in the verbatim text: the list of forbidden characters is

¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿


that is, the Unicode range 00A100BF.