\MakeShortVerb{\§} 和 \usepackage[utf8]{inputenc}

\MakeShortVerb{\§} 和 \usepackage[utf8]{inputenc}

我有一本十多年前出版的书。它的序言中包含以下代码:

\documentclass{article}

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

\usepackage{shortvrb}
\MakeShortVerb{\§}

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

现在我想将源文件转换为unicode。但是在将cp1251编码更改为utf8

\usepackage[utf8]{inputenc}

编译停止并显示错误消息,表明存在问题\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

如何避免这个问题?没什么可说的,我仍然想用它§作为短逐字文本的分隔符。包是否shortverbutf8编码兼容?

答案1

@egreg 又太快了。但我要准备午餐……

\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} 

在此处输入图片描述

答案2

问题是,在UTF-8中,§长度是两个字节,但\MakeShortVerb只需要一个。

我能提供的最好信息如下:

\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}

限制是,UTF-8 中以 开头的任何字符都<C2>不能出现在逐字文本中:禁用字符列表为

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

即 Unicode 范围00A100BF

在此处输入图片描述

相关内容