First I am sure, pdflatex can compile Tex file with Chinese file name without problem. For example, the Tex source content is as follows


save it as a file named "中文.tex" and run

pdflatex 中文.tex

everything is OK.

Now, in order to speed up the compilation, we make pre-compilation according to this link. That is to edit a file named "pre.tex" whose content is as follows


and run

pdflatex -ini -jobname="pre" "&pdflatex pre.tex\dump"

to generate a .fmt file called "pre.fmt"

now, we use this precompiled .fmt file in out tex source like

%& pre

if we save it as a file named "en.tex", and pdflatex en.tex works fine. But if we save it as a file named "中文.tex", then pdflatex 中文.tex will show errors like

enter image description here

What is wrong here? why precompile doesn't support Tex file with Chinese file name?

I upload the file "中文.tex" download here

  • Do you type the name of the file? Can you try typing pdflatex, and then drag&drop the file on the Terminal window? It looks like your terminal doesn't see the Chinese characters, so what you type is not what it needs to see. I'd try that. Don't forget the space after pdflatex. – Alenanno Dec 15 '15 at 13:39
  • @Alenanno drag is not working. – user15964 Dec 15 '15 at 13:42
  • @Alenanno I add a link to my file, maybe you would like to test it – user15964 Dec 15 '15 at 13:46
  • Well obviously pdflatex did open the file as it found the %& pre file and loaded the format but then wasn't able to continue. You should report this to the tex live mailing list. (But I would avoid such file names. There are not very portable.). – Ulrike Fischer Dec 15 '15 at 13:48
  • Did you try running pdftex -format=pre 中文.tex, instead of relying on the %& line? – egreg Dec 15 '15 at 13:50

You can see the cause here


Compare the two \show

Initially the bytes are all essentially inert and so the filename gets passed to the filesystem and would work, but after the class has been loaded the bytes have been made active and given definitions that enable typesetting of the characters but this means they expand to the wrong thing for the filename.

I don't have all the fonts to fully test this but I think it works if you change your format template to


% set high chars active at start of job
% After the commandline has been read, but before Tex starts reading the
% file contents, the tokens in \everyjob are run. 
% This loop sets every character between 127 and 255 to be catcode 13
% "active" which is the catcode they normally have after inputenc package
% or the ctexart class code.
\advance\count0 1

% set high chars inactive now for filename reading
% This loop sets every character between 127 and 255 to be catcode 12
% "other" which is the normal catcode for punctuation. this means that
% no special interpretation is done and the filename works as in a normal 
% format (where high characters are also not active until inputenc or
% similar is loaded. 
% Unlike the previous loop which is delayed in \everyjob
% This loop is executed here to make characters safe before the \dump
\advance\count0 1

So that the 8bit characters are not active until \everyjob is run, after the filename has been read.

  • Well, that's very interesting code. What's the e in \edef? – Alenanno Dec 15 '15 at 13:56
  • Thank you very much for the explanation. But I don't understand how to do this "use \string or \unexpanded to prevent expansion on the commandline" – user15964 Dec 15 '15 at 14:17
  • @Alenanno \edef is expanded def, macros in the replacement text get expanded at definition time, needed here to show that 中文 expands to typesetting commands in the second case – David Carlisle Dec 15 '15 at 15:09
  • @user15964 I have been off line, do you still need an example? (not sure how well my cygwin deals with filenames of that form, but I could try...) – David Carlisle Dec 15 '15 at 15:10
  • @DavidCarlisle oh, so that is command in linux right? But I am currently under windows using CMD. So the problem is pdflatex.exe not terminal, right? I think this brings another interesting question: what is the safest compile command line in windows CMD or linux terminal in cases of there will be nonstandard file name? I am not in a hurry, you can comment back when you have spare time. Thank you so much – user15964 Dec 15 '15 at 15:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.