[texworks] Manual: 5.2 Special comment strings - % !TeX jobname = "Some Other Name"

Reinhard Kotucha reinhard.kotucha at web.de
Sun Jul 14 02:10:55 CEST 2019

Hi Paul,
nowadays these magic lines are only understood by text editors.  Long
time ago there had been magic lines which were understood by the TeX
engine in order to load the appropriate format file.  But nowadays
this doesn't work anymore because we have more than one

On 2019-07-13 at 20:27:03 +1200, Paul A Norman wrote:

 > Its useful for example when you are using this package
 > \usepackage[1-9,18-24,131-136,401, 429-431]{pagesel}

There is a much better solution.  Add the following lines to the
preamble of your main document:


Now create a second document, for instance "selection-1.tex":

  \newcommand\myselection{1-9,18-24,131-136,401, 429-431}

Replace "mainfile" with the actual name of your document.

The line


needs some explanation.  It doesn't change the name of the output file
because it has already been determined from the command line and
cannot be changed later.

However, LaTeX is using \jobname in order to assemble names of
auxiliary files (for instance \jobname.aux).  Thus, the line above
allows "selection-1.tex" to steal auxiliary files created by

The advantages of this approach are:

    * Add a few lines to the main document and never touch it again in
      order to select other page ranges.

    * You can create as many "selection-*.tex" files as you want
      without the need to edit one and the same file again and again.

    * Auxiliary files are stolen from the master document and don't
      have to be created again.

    * No need to change the internal behavior of TeX engines.


Reinhard Kotucha                            Phone: +49-511-3373112
Marschnerstr. 25
D-30167 Hannover                    mailto:reinhard.kotucha at web.de

More information about the texworks mailing list