[OS X TeX] jobname

Alain Schremmer schremmer.alain at gmail.com
Mon Apr 23 17:51:02 CEST 2007


I am getting back to the issue of trying to get \jobname work across  
included files.

On Jan 24, 2007, at 9:37 PM, Alain Schremmer wrote:

> The code given at
>
> http://www.tex.ac.uk/cgi-bin/texfaq2html?label=filename
>
>    \def\ThisFile{\jobname}
>    \newcounter{FileStack}
>    \let\OrigInput\input
>    \renewcommand{\input}[1]{%
>      \stackinput{#1}{\OrigInput}%
>    }
>    \newcommand{\stackinput}[2]{%
>      \stepcounter{FileStack}%
>      \expandafter\let
>        \csname NameStack\theFileStack\endcsname
>        \ThisFile
>      \def\ThisFile{#1}%
>      #2{#1}%
>      \expandafter\let\expandafter
>        \ThisFile
>        \csname NameStack\theFileStack\endcsname
>      \addtocounter{FileStack}{-1}%
>    }
>
> gives me "This makes 100 errors; please try again"

Then,

> Ross Moore wrote:
>
>> This coding doesn't seem to have been well-tested with
>> modern LaTeX. It falls foul of things that happen both
>> at  \begin{document}  and  \end{document} .
>>
>> However, it can be easily fixed as follows:
>>
>>   \def\ThisFile{\jobname}
>>    \newcounter{FileStack}
>>    \newcommand{\recordinput}[1]{%  <<---  new name
>>      \stackinput{#1}{\OrigInput}%
>>    }
>>    \newcommand{\stackinput}[2]{%
>>      \stepcounter{FileStack}%
>>      \expandafter\let
>>        \csname NameStack\theFileStack\endcsname
>>        \ThisFile
>>      \def\ThisFile{#1}%  <<---- \edef might be better here !
>>      #2{#1}%
>>      \expandafter\let\expandafter
>>        \ThisFile
>>        \csname NameStack\theFileStack\endcsname
>>      \addtocounter{FileStack}{-1}%
>>   }
>>
>> %%  delay the re-definition of  \input until later
>>  \AtBeginDocument{%
>>    \let\OrigInput\input
>>    \let\input\recordinput
>>  }
>> %%  set it back at the end of the document
>>  \AtEndDocument{\let \input \OrigInput}
>
> I will test tomorrow.

Well, I finally did test it and I still have a problem which is  
getting a bit acute because of the huge numbers of files in the real  
situation.

I have a minimal example but since it involves included files and  
folders, I can only describe it here (But I will gladly send it).

0)The preamble is:

		\documentclass[11pt]{book}
		\usepackage{graphicx}
		\usepackage{calc}	
		\usepackage{ifthen}
		\usepackage{amsmath}
		\usepackage{amsthm}
		\usepackage{url}
			
		 			\newtheorem{exercise}{Exercise}[chapter]
		
					\newboolean{includingExercises}
						% defaults to false
					\newcommand{\includeExercises}[1]{%
					\ifthenelse{\boolean{includingExercises}}
						% if true, do the  first thing, otherwise the second.
					{%
					    \input{#1}% true part
					}{%
					    {\url{#1}}% else part
					}%
					} 	
	
		\graphicspath{
		{../Figures/Chapters/10/}
		{../../Figures/Chapters/10/}
		{../Figures/Exercises/10/}
		{../../Figures/Exercises/10/}
		}

I have in fact two versions of the mini-example:

1) The folder ActualName contains

---A folder, called EDITunit, containing a file called 10 which has  
just contents.
				It starts with %!TEX root = ../PRINTunit/10.tex
				It ends with \includeExercises{../Exercises/10}

---A folder, called Exercises, containing a file, also called 10,  
which has a set of exercises for 10.

---A folder, called HomeWorks, containing a folder, called Math 000,  
containing a root file, called 1, whose purpose is to typeset the set  
of exercises in 10 under the heading "Math 000-HomeWork 1". It starts  
with the preamble and has
				\setboolean{includingExercises}{true}
				\includeExercises{../../Exercises/10}.

---A folder, called PRINTunit, containing a root file, also called  
10, whose purpose is to typeset the contents of file 10 in EDITunit.

---A folder, called TextBooks, containing a root file, called  
Math000Book, whose purpose is to typeset the whole book for Math000.  
It starts with the preamble and has
				\setboolean{includingExercises}{true}
				\include{../EDITunit/10}

---A folder, called Figures, containing:
		--A folder, called Chapters, containing a folder, called 10,  
containing a pdf file called 10-1
		--A folder, called Exercises, containing a folder, called 10,  
containing a pdf file called 10-1x

2) The folder JobName contains exactly the same as the folder  
ActualName except that:

---I included the above code with include instead of input in the  
preamble of the three root files: HomeWorks > Math000 > 1, PRINTunit  
 > 10, TextBooks > Math000Book

---I replaced 10 by \jobname:
		--in the \includeExercises(../Exercises/10} in the file EDITunit >  
10 that calls the file Exercises > 10.
		--in the \include{../EDITunit/10} in the root file PRINTunit > 10  
that calls EDITunit > 10  to typeset it all by itself,
		--in the \include{../EDITunit/10} in the root file TextBooks >  
Math000Book that calls EDITunit > 10 to typeset it within the whole  
textbook.
		--in the \includegraphics{10-1} in the file EDITunit > 10
		--in the  \includegraphics{10-1x} in the file Exercises > 10.

---I replaced 1 by \jobname:
		--in the heading   \noindent{\Large  \textsc{Math} \textbf{000}   
Homework 1} in the file HomeWorks > Math000 > 1


3) While everything in ActualName typesets as it should, when I try  
to typeset in JobName,

		HomeWorks > Math000 > 1 typesets as it should
		PRINTunit > 10 typesets as it should
but
		TextBooks > Math000Book doesn't work (with either \def or \edef) as  
LaTeX complains about  \includegraphics{\jobname-1}

Very hopeful regards
--schremmer














------------------------- Helpful Info -------------------------
Mac-TeX Website: http://www.esm.psu.edu/mac-tex/
TeX FAQ: http://www.tex.ac.uk/faq
List Archive: http://tug.org/pipermail/macostex-archives/
List Reminders & Etiquette: http://www.esm.psu.edu/mac-tex/list/





More information about the macostex-archives mailing list