Defining the pdf output file within the document file using %& -job-name

My understanding is that if I create a file called noName.tex with the first line

%& -jobname=myName


then when I run pdflatex on that file, the output file will be named myName.pdf rather than noName.pdf, just as if I'd typed

pdflatex -jobname=myName noName.tex


But in the following example, the first line is ignored by pdflatex, and the output is named noName.pdf.

Here is noName.tex:

%& -job-name=myName
\documentclass{minimal}
\begin{document}
Hello World
\end{document}


Could somebody advise what the correct syntax would be please? Thanks very much.

The version of pdflatex I'm using is:

This is pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian) (format=pdflatex 2014.6.25)

• Where exactly have you gotten the idea that this should be supported (not saying that it isn't?, I've never seen it before) Jan 24, 2016 at 12:09
• as @daleif ask what is the editor you use? This works fine for me with TeXstudio. Jan 24, 2016 at 17:28
• I saw reference to it in this thread. But elsewhere also. I'm using linux, so simply running pdflatex from the command line. TeXstudio obviously has a lot of additional wrapping. Jan 24, 2016 at 19:35
• The line %& -jobname=myName is one of these so-called magic comments, which can be interpreted by some editors (TeXstudio, TeXworks). This is hence not an intrinsic feature of pdftex and compiling from the command line will thus result in those magic comments being ignored. Jan 25, 2016 at 12:21
• @HenriMenke No, this is a magic line for the TeX engine and is not interpreted by editors, as far as I know. Some implementations of TeX allow -jobname there some don't: MiKTeX does, TeX Live doesn't. Jan 25, 2016 at 14:52

The %& magic line has been supported by implementations of TeX from many years. However, the feature is implemented differently in the various TeX distributions.

Note that no editor/front-end I know of interprets such a line: this is specific for the TeX engine.

In TeX Live, the line can contain only the specification of a format to be loaded and a TCX file, see section 3.5.2.2 in the documentation of Web2c (texdoc web2c, page 11 for TeX Live 2015):

%&format -translate-file=tcxfile


Either part can be empty. Note that, in TeX Live, Knuth TeX doesn't honor this magic line.

As far as I know, other command line options such as -jobname can be specified with MiKTeX. They'll definitely not work with TeX Live.

• I can confirm that the pdflatex executable included in MacTeX (2020) ignores the “magic comment” %& -jobname=myName or %& -job-name=myName. By contrast, the pdflatex executable included in MiKTeX for the Mac does take the magic comment %& -job-name=myName into account. Jun 27, 2020 at 10:47

If you are using TeXstudio with TeX Live/MacTeX, you can include the line

% !TeX TXS-program:compile = txs:///pdflatex/[-jobname=myName]

at the beginning of your document to specify myName as the name of the output file.

• Great! Thanks dude! Jan 16 at 18:24