2

When I compile a main file main.tex with the packages subfiles and xeCJK, I get the error Improper alphabetic constant. It works well when compiling the subfile

Here show main.tex (which does not work):

\documentclass{article}
\usepackage{xeCJK}
\usepackage{subfiles}
\begin{document}
MAIN test
\subfile{sub.tex}
\end{document}

sub.tex (which works):

\documentclass[main.tex]{subfiles}
\begin{document}
SUB test
\end{document}

and a part of the log file main.log:

./sub.tex:2: Improper alphabetic constant.
<to be read again> 
                   \__xeCJK_ambiguous_char:n 
l.2 \begin{document}
                    
A one-character control sequence belongs after a ` mark.
So I'm essentially inserting \0 here.

The list is below of versions of packages and XeTeX I use.

  • subfiles: 2.0
  • xeCJK: 3.8.6
  • XeTeX: 3.14159265-2.6-0.999992 (TeX Live 2020/W32TeX)

2 Answers 2

2

The problem is that xeCJK adds code to one of the document hooks and as subfiles doesn't empty this hook the code is processed twice, and in this case it harms. You can provoke a similar error with

\documentclass{article}
\usepackage{xeCJK}
\ExplSyntaxOn
\__xeCJK_patch_text_command:
\__xeCJK_patch_text_command:
\ExplSyntaxOff
\end{document}

The first call to the patch works, but the second fails.

A structural similar error can be shown with this:

\begin{filecontents}{sub.tex}
\documentclass{subfiles}
\begin{document}
SUB test
\blub
\end{document}
\end{filecontents}

\documentclass{article}
\AddToHook{env/document/before}{\newcommand\blub{abc}}
\usepackage{subfiles}
\begin{document}
%\RemoveFromHook{env/document/before}[*]
MAIN test \blub
\subfile{sub.tex}
\end{document}

By adding \RemoveFromHook{env/document/before}[*] you can remove the code. Then is works again. subfiles should probably do this, before loading a subfile.

But xeCJK could avoid the problem too by using \AddToHookNext{env/document/before} (\hook_gput_next_code:nn) instead of \AddToHook for code that should be executed only once. Or it could (that is probably even better) use the begindocument/before hook instead).

0

With version 2020/10/24 v2.1 of the subfiles package, this problem is solved. At the moment, this version is not yet on CTAN, but only on Github.

You must log in to answer this question.

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