索引期间出现奇怪的错误消息“CLOSED INPUT BUFFERED FILE-STREAM CHARACTER”

索引期间出现奇怪的错误消息“CLOSED INPUT BUFFERED FILE-STREAM CHARACTER”

我正在使用的解决方案使用 siunitx 包对二进制单元进行索引unexpanded。这不仅解决了我发布的具体问题,而且似乎还解决了许多其他问题。但是,如果参数中有双引号,则似乎会有些困难,这会导致

Reading raw-index "/var/folders/70/.../T/N728p7zZMX"...
ERROR: READ: input stream #<CLOSED INPUT BUFFERED FILE-STREAM CHARACTER #P"/var/folders/70/.../T/N728p7zZMX" @3> ends within a string

其中...是一些随机生成的路径。

MWE 仅在引用的问题的解决方案中添加了一行

代码:

\documentclass{article}
\usepackage{imakeidx}
\usepackage{xparse}
\usepackage{siunitx}
\usepackage{xcolor}

%% https://tex.stackexchange.com/questions/50712/automatically-convert-quotations-in-the-form-of-abc-to-become-abc
\usepackage{csquotes}
\MakeOuterQuote{"}


\usepackage{hyperref}

\newcommand*\lettergroup[1]{\subsection{#1}}

\newcommand*{\IndexWithName}[2]{%
    % #1 = word to index
    % #2 = index name
    \index[#2]{#1}%
}

\NewDocumentCommand{\FormatIndexEntry}{mm}{%
    \textcolor{blue}{#1} #2%
}


%% Defer the binary units until AFTER \begin{document} as per
%% https://tex.stackexchange.com/questions/287579/how-to-overwrite-siunitxs-binary-prefixes
\sisetup{binary-units=true}
\AtBeginDocument{%
    \DeclareSIUnit\bit{\textcolor{red}{bit}}%
}

\NewDocumentCommand{\AddIndexEntry}{%
    O{}% #1 = index name
      m% #2 = word to index this under
      m% #3 = indexed term
      m% #4 = symbol
}{%
    \expandafter\IndexWithName\expandafter{%
        #2!#3@\FormatIndexEntry{#3}{\unexpanded{\unexpanded{#4}}}%
    }{#1}%
}
\newcommand{\indexopt}[2]{\index[#2]{#1}}

\makeindex[title={Main Index},columns=1,program=texindy]
\makeindex[title={Name Index},columns=1,program=texindy,name=Name]
\indexsetup{level=\section}

\begin{document}

\SI{1}{\bit}

\AddIndexEntry[Name]{Bytes}{Bit}{symbol: \si{\bit}}
\AddIndexEntry[Name]{Bytes}{Bit}{text using "quotes"}% <---- This is a problem.

\clearpage 
\setcounter{secnumdepth}{0}
\printindex[Name]
\end{document}

答案1

该字符"在索引文件中很特殊,应像这样引用

""

另一方面,"在 LaTeX 文档中永远不应单独使用,但可以与以下方式一起使用csquotes

\documentclass{article}
\usepackage{imakeidx}
\usepackage{xparse}
\usepackage{siunitx}
\usepackage{xcolor}
\usepackage{csquotes}
\usepackage{hyperref}

\MakeOuterQuote{"}

\newcommand*\lettergroup[1]{\subsection{#1}}

\newcommand*{\IndexWithName}[2]{%
    % #1 = word to index
    % #2 = index name
    \index[#2]{#1}%
}

\NewDocumentCommand{\FormatIndexEntry}{mm}{%
    \textcolor{blue}{#1} #2%
}


%% Defer the binary units until AFTER \begin{document} as per
%% http://tex.stackexchange.com/questions/287579/how-to-overwrite-siunitxs-binary-prefixes
\sisetup{binary-units=true}
\AtBeginDocument{%
    \DeclareSIUnit\bit{\textcolor{red}{bit}}%
}

\NewDocumentCommand{\AddIndexEntry}{%
    O{}% #1 = index name
      m% #2 = word to index this under
      m% #3 = indexed term
      m% #4 = symbol
}{%
    \expandafter\IndexWithName\expandafter{%
        #2!#3@\FormatIndexEntry{#3}{\unexpanded{\unexpanded{#4}}}%
    }{#1}%
}
\newcommand{\indexopt}[2]{\index[#2]{#1}}

\makeindex[title={Main Index},columns=1,program=texindy]
\makeindex[title={Name Index},columns=1,program=texindy,name=Name]
\indexsetup{level=\section}

\begin{document}

\SI{1}{\bit}

\AddIndexEntry[Name]{Bytes}{Bit}{symbol: \si{\bit}}
\AddIndexEntry[Name]{Bytes}{Bitq}{text using ""quotes""}% <---- This is a problem.

\clearpage 
\setcounter{secnumdepth}{0}
\printindex[Name]
\end{document}

在此处输入图片描述

相关内容