[texworks] %!TEX tags

Alain Schremmer schremmer.alain at gmail.com
Sat Jun 26 16:59:28 CEST 2010

On Jun 26, 2010, at 3:36 AM, Stefan Löffler wrote:

> Hi,
> Am 2010-06-24 18:07, schrieb Alain Schremmer:
>> Can TeXworks respond to lines such as the following:
>>     %!TEX root =../FOO/\jobname.tex
>> Please note the use of \jobname which would need to have been
>> specially taken care of. And, unfortunately, I am no programmer and
>> thus unable to check the code for myself.
> I've posted your feature request and a patch at
> http://code.google.com/p/texworks/issues/detail?id=384.
>> I am a completely satisfied user of TeXShop and am inquiring in
>> consideration of the windows users of my stuff which uses this line
>> systematically.
> I think this is an intriguing feature, though I'm not sure if most
> "standard" users will know about the meaning of \jobname.

You are right, \jobname is not well known: it appears in passing on  
page 754 of Companion 2ed. But it is a most useful command when you  
have many similar files made from a template. Here is a typical example:

The way I use the %!TEX root tag is as follows:

First, I have two folders: Contents and Controls

---In the Contents folder I have files named 0.tex, (that's for the  
Preface),1.tex, 2.tex etc each of which starts as follows:

		%!TEX root = ../Controls/\jobname.tex
		\chapter{My Chapter One}
			Some text

---In the Controls folder, I have files also named 0.tex, 1.tex,  
2.tex etc each of which is just a copy of:

			\addtocounter{page}{0}%Must be adjusted manually from the WholeBook
			\addtocounter{chapter}{\jobbame-1}%This, though, is automatic

---Thirdly, I have a folder WholeBook which contains the file MyBook  
which is the usual root file:


Thus, I can compile a chapter either from the Content file or from  
the Control file will typeset just the chapter.

In fact, for the sake of symmetry, I am now using the following  
variation on the above theme

I have only the two folders: Contents and Controls in which I have  
the same files as above but also, in addition:

---In the Contents folder:

The file ALL.tex:

	%!TEX root = ../Controls/\jobname.tex
		\include{../Contents/0}%Preface to be numbered along with the  
contents, etc

---In the Controls folder
The file ALL.tex:

			\include{../Text-contents/99}%That's the GNU FDL

> Is this astandard TeXShop feature (in which case I think we should  
> keep it, for
> the sake of cooperation)?

What is a feature of TeXShop is that, much to the disbelief of many,  
it understands \jobname in that first line. Through sheer idiot's  
luck, I knew and used that but it took Koch to explain why. I am  

So I looked at the routine "decodeFile" and discovered this comment:

      // added by John A. Nairn
   // get full path name for possible relative file name in relFile
   // relative is from home

and the last lines of the routine read

	// see if \jobname is there
	searchString = [self filterBackslashes:@"\\jobname"];
	aRange = [saveName rangeOfString:searchString options:NSLiteralSearch];
	if(aRange.location == NSNotFound)
		return saveName;

	// replace \jobname(s)
	saveTemp = [NSMutableString stringWithString:saveName];
	[saveTemp replaceOccurrencesOfString:searchString withString:jobname  
								   range:NSMakeRange(0,[saveName length])];
	return [NSString stringWithString:saveTemp];

> If not, maybe it would be better to change
> this to something a little more intuitive, like "$basename" (keeping
> with the notation for typesetting tools).

Here I am not following you. What is "$basename"? It does not seem to  
appear in Companion 2ed.

But it makes me think of  an extremely useful command in Didier  
Verna's FINK. Here is how I am using it:

{%begin Quiz? true

Doesn't look like much but given that I have 900 such pages ...

I have forgotten now but, at one point, it would have made my life a  
lot easier had I been able to use FINK's tools in that first line  
tag. Unfortunately, John A. Nairn does not seem to have known about it.

> Maybe we could even do both...

So, yes, I think that it would be a good think to have them both in  
TeXWorks.  More specifically, right now, the system for developing  
and managing ancillaries which is freely downloadable from


"should" work with editors under Windows but would most not likely  
not be able to typeset from the Contents files. With TeXWorks  
behaving like TeXShop in that particular, I could write a single set  
of instructions under TeXWorks for the users interested in using the  
ancillaries of my texts but absolutely not in dealing with LaTeX--- 
i.e. teachers who are mostly in the Windows world. But also for  
authors interested in using the "system" to write ancillaries for  
their own text. The system is described in a forthcoming piece in  

Grateful---and hopeful---regards

More information about the texworks mailing list