![语言和未定义的控制序列 \caption](https://linux22.com/image/469301/%E8%AF%AD%E8%A8%80%E5%92%8C%E6%9C%AA%E5%AE%9A%E4%B9%89%E7%9A%84%E6%8E%A7%E5%88%B6%E5%BA%8F%E5%88%97%20%5Ccaption.png)
我尝试用 luatex 编译以下代码
\documentclass[a4paper,11pt,latvian]{article}
\usepackage[margin=2.5cm]{geometry} % for margins on a A4paper
\usepackage[shorthands=off,bidi=basic]{babel}
\usepackage[skip=5.5pt]{caption}[2020/09/12]
\usepackage[Export]{adjustbox} % #124
\usepackage{titlesec}
\begin{document}
\begin{figure}[!htbp]
\input{images/6195f2d3c08c94fdc73f8d014f5614648c81ee8b.tex}
\vspace{-11pt}
\caption{%
Sample text%
}
\end{figure}
\end{document}
并得到以下异常:
Package luatex.def Info: images/6195f2d3c08c94fdc73f8d014f5614648c81ee8b.png u
sed on input line 3.
(luatex.def) Requested size: 1259.70319pt x 917.42528pt.
)
! Undefined control sequence.
\the@chapter ...ed \relax \else \ifnum \c@chapter
>\z@ \thechapter \fi \fi
l.11 \caption{
%
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.
我已将日志文件发布在https://justpaste.it/cvwv5
我认为它与 有某种关联,latvian
但我不确定。更改为 egfrench
即可编译。
答案1
不确定你为什么要加载bidi=basic
拉脱维亚文档。无论如何,这不是问题。
如果你尝试最小化从
\documentclass[a4paper,11pt]{article}
\usepackage[latvian,shorthands=off]{babel}
\begin{document}
\begin{figure}[!htbp]
\caption{Sample text}
\end{figure}
\end{document}
您不会看到任何错误。但添加后titlesec
会出现错误。如果我们注释掉对的调用babel
,错误就会再次消失。
因此问题在于与babel-latvian
和 的兼容性titlesec
。
会发生什么?latvian.ldf
我们发现
111 \gdef\the@chapter{%
112 \ifx\chapter\undefined\relax\else
113 \ifnum\c@chapter>\z@\thechapter\fi\fi}
[...]
165 \def\thefigure{\the@chapter\@arabic\c@figure.}
(行号仅供参考)这是问题的原因,titlesec
因为
\expandafter\ifx\csname chapter\endcsname\relax
测试\chapter
未定义应该总是是
\@ifundefined{chapter}{<true>}{<false>}
另一种可能性是
\ifcsname chapter\endcsname <true>\else<false>\fi
这并不chapter
等同于\relax
当前使用的代码titlesec
。
但是,\ifx\chapter\undefined
这绝对不是最好的主意。
解决方法:
\documentclass[a4paper,11pt]{article}
\usepackage[latvian,shorthands=off]{babel}
\usepackage{titlesec}
%%% ensure \chapter passes the \ifx\chapter\undefined test
\let\chapter\undefined
%%%
\begin{document}
\begin{figure}[!htbp]
\caption{Sample text}
\end{figure}
\end{document}