2

I try to compile the following code with 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}

and get the following exception:

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.

I've publish the log file under https://justpaste.it/cvwv5

I think its somehow related with latvian but I'm not sure. Changing to e.g. french compiles.

1 Answer 1

2

Not sure why you load bidi=basic for a Latvian document. Anyway, that's not the problem.

If you try minimizing the example starting from

\documentclass[a4paper,11pt]{article}
\usepackage[latvian,shorthands=off]{babel}

\begin{document}

\begin{figure}[!htbp]
\caption{Sample text}
\end{figure}

\end{document}

you'll see no error. But upon adding titlesec the error appears. If we comment out the call to babel, the error disappears again.

Thus the problem is in compatibility with babel-latvian and titlesec.

What happens? In latvian.ldf we find

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

(line numbers just for reference) which is the cause of the problem, because titlesec does

\expandafter\ifx\csname chapter\endcsname\relax

Testing for \chapter being undefined should always be

\@ifundefined{chapter}{<true>}{<false>}

An alternative possibility is

\ifcsname chapter\endcsname <true>\else<false>\fi

that wouldn't make chapter equivalent to \relax like the code currently used by titlesec does.

However, \ifx\chapter\undefined is definitely not the best idea.

Workaround:

\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}
4
  • Thx for the detailed analysis. I'll test tomorrow. When I read it properly than that's a bug in the package titelsec, right? Or should this be fixed in Babel? More the question where to raise an issue
    – LeO
    Sep 25 at 19:01
  • The bidi option is more as some kind of fallback if we include Arabic text. Won't apply for the MWE.
    – LeO
    Sep 25 at 19:04
  • @LeO In my opinion it should be fixed in both.
    – egreg
    Sep 25 at 19:47
  • I've also filed a ticket for Babel (github.com/latex3/babel/issues/264). Just to clarify, the \let\chapter\undefined command makes sure that \chapter is defined somehow. Does it have any negative effect if I leave it there, e.g. for other languages that have no problems? Or simpler: Can I leave the command in general without any negative impact?
    – LeO
    Sep 26 at 6:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .