Hi everybody,
do not get me wrong about this post, but I was wondering if someone could help me writing this TMscript. Or maybe it is honest to say write this script. The idea is the following:
- I have a big LaTeX project, so I divided the report in several documents. - Let's say: - master.tex - part1.tex - part2.tex - Basically master.tex includes all following documents, so in case I would typeset the master.tex file I would get the whole document. - There is a TM-function which allows me to set the master file in my project, so that typesetting any file (for example part1.tex) actually typesets the master.tex file. - But this takes time so it would be nicer to typeset just the file I am working on right now. - My Idea is: 1) change the first line of part1.tex (and or part2.tex) to %% TM_LATEX_COMMAND%% Head include %% 2) add a line in the master.tex somewhere after \begin{document} : %% TM_LATEX_COMMAND%% Head %% 3) when typesetting the script looks for the line (see (2)). 4a) if there is no "%%TM_LATEX_COMMAND%%Head%%" it will go on like it does right now 4b) if there is the line "%%TM_LATEX_COMMAND%%Head%%" then I takes the lines before " %%TM_LATEX_COMMAND%% Head %% " and puts them on top of the typsetted file. It also adds an \end{document} and then typesets all. - what I do not know is how pdfsync works then, but since I do not know how to write this little script I could not try out.
It would be great if someone could help me or send the website where this is already posted. However, I would also appreciate some helpful comments on how to write the script by myself.
Tanks Christoph
~~~~~ Christoph Biela
cbiela@gmail.com
I also like to divide large projects and use a pretty short main document that creates the environment but then mainly consists of a list of includes. While I work on one part I have the other includes commented out. In any text editor it's easy to comment a selection at once.
This way I always use the same environment (with pdfsync etc.) but I shorten compile times while working on just one part.
But this might not fit your way of working, of course.
Regards,
/Peder Axensten
On 18 maj 2006, at 18.00, Christoph Biela wrote:
Hi everybody,
do not get me wrong about this post, but I was wondering if someone could help me writing this TMscript. Or maybe it is honest to say write this script. The idea is the following:
- I have a big LaTeX project, so I divided the report in several
documents.
- Let's say:
- master.tex
- part1.tex
- part2.tex
- Basically master.tex includes all following documents, so in case
I would typeset the master.tex file I would get the whole document.
- There is a TM-function which allows me to set the master file in
my project, so that typesetting any file (for example part1.tex) actually typesets the master.tex file.
- But this takes time so it would be nicer to typeset just the file
I am working on right now.
- My Idea is:
- change the first line of part1.tex (and or part2.tex) to %%
TM_LATEX_COMMAND%% Head include %% 2) add a line in the master.tex somewhere after \begin{document} : %%TM_LATEX_COMMAND%% Head %% 3) when typesetting the script looks for the line (see (2)). 4a) if there is no "%%TM_LATEX_COMMAND%%Head%%" it will go on like it does right now 4b) if there is the line "%%TM_LATEX_COMMAND%%Head%%" then I takes the lines before " %%TM_LATEX_COMMAND%% Head %% " and puts them on top of the typsetted file. It also adds an \end{document} and then typesets all.
- what I do not know is how pdfsync works then, but since I do not
know how to write this little script I could not try out.
It would be great if someone could help me or send the website where this is already posted. However, I would also appreciate some helpful comments on how to write the script by myself.
Tanks Christoph
Christoph Biela cbiela@gmail.com ______________________________________________________________________ For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
While TextMate may have a nice solution for this, there's also the LaTeX way of solving this.
Save the attached document as header.tex, adapt it to your needs and source that on the first line of each section.
And in your whole document use the following lines before you source the others.
\newcommand{\setflag}{\newif \ifwhole \wholetrue}
If desired, you can also include a static chapter/section counter like so: \setcounter{chapter}{1}
But then again, if you use latexmk.pl, you aren't gonna need that.
Jeroen.
\providecommand{\setflag}{\newif \ifwhole \wholefalse} \setflag
\ifwhole\else \documentclass[11pt,a4paper,twoside,openright]{report} \usepackage{url} \usepackage[british]{babel} \usepackage{verbatim} \usepackage{eurosym} \usepackage{graphicx} \usepackage{tabularx} % \usepackage{side} \usepackage{rotating} \usepackage{fancyhdr} \usepackage{theorem}
\pagestyle{fancyplain} \lhead{}\rhead{}\cfoot{}\chead{} %\lfoot[\fancyplain{}{\bfseries\thepage}]{} \rfoot[]{\thepage} \lfoot[\thepage]{} \renewcommand{\headrule}{}
\setlength{\oddsidemargin}{0.55in} \setlength{\evensidemargin}{0.55in}
{\theoremstyle{break} {\theorembodyfont{\normalfont} \newtheorem{example}{Example}}} {\theoremstyle{break} \newtheorem{definition}{Definition}[chapter]} \newtheorem{defin}[definition]{Definition}
\def\mbarrow{\stackrel{\textnormal{\tiny{\ MB}}}{\longleftarrow}} \def\notmodels{\mathrel|\joinrel\neq}
\begin{document} \fi
I wanted to elaborate a bit on Jeroen's explanation for those not very familiar with the "more obsure" TeXnical commands. But first, let me bring to everyone's attention the \includeonly command. Say you have in your master document:
\include{chapter1} \include{chapter2} \include{chapter3}
and you have typeset them once, and hence the .aux files with the reference and counter information have been created. Then you want to only work on chapter 3. You can add the command: \includeonly{chapter3} before those includes, and then, when you typeset, only chapter 3 gets typeset, BUT the .aux files from the other chapters are being used. In other words, this will STILL be typeset as "chapter 3", instead of becoming "chapter 1", keeping things just a bit more neat. So one way to arrange things is to have the command as:
\includeonly{ chapter1, chapter2, chapter3, }
and then to comment out some of these lines depending on what chapters you want typeset.
Ok, on to Jeroen's explanation, which basically answers the question: "How to have a file that can be typeset normally, but that when include'd into other documents it will compile just fine." The question is in essence: How can I make the header and footer stuff of a document conditional as to whether the document is included or not. The idea is to create two extra files, a header.tex and a footer.tex. The header should have the following:
\providecommand{\setflag}{\newif \ifwhole \wholefalse} \setflag \ifwhole\else \documentclass[11pt,a4paper,twoside,openright]{report} % your header stuff here, usepackages etc \begin{document} \fi
We'll explain what all this does in a minute. Then the footer should contain:
\ifwhole\else \end{document} \fi
Finally, your individual "chapter" files should have the following form:
\input{header.tex} % your chapter text here \input{footer.tex}
while your master document should have the form:
\input{header.tex} \renewcommand{\setflag}{\newif \ifwhole \wholetrue} % your chapter includes here: \include{chapter1} \include{chapter2} ... \renewcommand{\setflag}{\newif \ifwhole \wholefalse} \input{footer.tex}
Ok, now you are set. Let's explain what has happened here:
Let's start with the text in header.tex. The first line tells TeX to provide the command \setflag with definition {\newif\ifwhole \wholefalse}. \providecommand checks to see if the command is already present, and if it is not it creates it. When we compile this chapter file directly, this is the first command encountered, so it hasn't been created yet, so it gets created. the second line then executes it.
Ok, so what does \setflag do? It runs the commands \newif\ifwhole \wholefalse. \newif is a TeX primitive. What it does is kind of complicated: It takes one argument, which should be of the form \iffoo. In this case it is \ifwhole (we could also have written this as \newif{\ifwhole}). So, when \newif\iffoo is run, the result is that three new commands are being defined. Two of these commands are \footrue and \foofalse, and they just set some "magical variable" to true or false respectively. The third new command is the command \iffoo, which is an "if" command an returns true or false depending on whether \footrue or \foofalse is the last command executed.
In out case, after the triple \ifwhole,\wholetrue,\wholefalse has been defined, our program runs \wholefalse. So this means that when \ifwhole gets called in the next line, it will return true.
Ok, let's move to this next line now. TeX "if" clauses have exactly this syntax: \ifclause % stuff that happens when \ifclause is true \else % stuff that happens when \ifclause is false \fi
In our case, \ifwhole is now false, hence the entire \else block gets executed, and we get our header, and later on our footer, hence the document can be compiled.
Now let's see what happens when we are in our master document. Then we again include the header in the same way. Then we have the \renewcommand that redefines the \setflag command to be returning \wholetrue when executed. then we go on to include the various chapters. When header.tex in loaded in them, the \providecommand will not do anything since \setflag has already been defined, hence its definition with \wholetrue is the one that will be used. This now means that the \ifwhole test succeeds, hence the \else part is not executed, so the header data (and similarly the footer data) does not get inserted again (avoiding the disaster that would arise if it did).
Finally, after all the chapters have been included, we redefine the command again to make sure that the footer gets inserted. (I guess you could have directly used \end{document} in the master file instead of trying to include the footer file.)
One little question that might have arisen is why I used \input instead of \include. The reason is that by design (don't ask me why, I don't know) you cannot have nested \include's, while you could have nested \input's. The difference between the \input'ed files and the \include'd files is that the \include'd files generate their own .aux files, while the \input'ed files don't. I am guessing pdfsync might also not work with \input'ed files, but I haven't tested this.
Sorry for the long post, I hope it was interesting to some people.
Haris
That's it thanks!!!
This is a really nice and handy thing. However, somehow this all stopped working and then I only got it working after writing.
\renewcommand{\setflag}{\newif \ifwhole \wholefalse} \setflag % was somehow needed \input{foot.tex}
Does anyone know why? Is this related to TextMate?
Thanks Christoph
On 2006-05-19, at 01:53, Charilaos Skiadas wrote:
I wanted to elaborate a bit on Jeroen's explanation for those not very familiar with the "more obsure" TeXnical commands. But first, let me bring to everyone's attention the \includeonly command. Say you have in your master document:
\include{chapter1} \include{chapter2} \include{chapter3}
and you have typeset them once, and hence the .aux files with the reference and counter information have been created. Then you want to only work on chapter 3. You can add the command: \includeonly{chapter3} before those includes, and then, when you typeset, only chapter 3 gets typeset, BUT the .aux files from the other chapters are being used. In other words, this will STILL be typeset as "chapter 3", instead of becoming "chapter 1", keeping things just a bit more neat. So one way to arrange things is to have the command as:
\includeonly{ chapter1, chapter2, chapter3, }
and then to comment out some of these lines depending on what chapters you want typeset.
Ok, on to Jeroen's explanation, which basically answers the question: "How to have a file that can be typeset normally, but that when include'd into other documents it will compile just fine." The question is in essence: How can I make the header and footer stuff of a document conditional as to whether the document is included or not. The idea is to create two extra files, a header.tex and a footer.tex. The header should have the following:
\providecommand{\setflag}{\newif \ifwhole \wholefalse} \setflag \ifwhole\else \documentclass[11pt,a4paper,twoside,openright]{report} % your header stuff here, usepackages etc \begin{document} \fi
We'll explain what all this does in a minute. Then the footer should contain:
\ifwhole\else \end{document} \fi
Finally, your individual "chapter" files should have the following form:
\input{header.tex} % your chapter text here \input{footer.tex}
while your master document should have the form:
\input{header.tex} \renewcommand{\setflag}{\newif \ifwhole \wholetrue} % your chapter includes here: \include{chapter1} \include{chapter2} ... \renewcommand{\setflag}{\newif \ifwhole \wholefalse} \input{footer.tex}
Ok, now you are set. Let's explain what has happened here:
Let's start with the text in header.tex. The first line tells TeX to provide the command \setflag with definition {\newif\ifwhole \wholefalse}. \providecommand checks to see if the command is already present, and if it is not it creates it. When we compile this chapter file directly, this is the first command encountered, so it hasn't been created yet, so it gets created. the second line then executes it.
Ok, so what does \setflag do? It runs the commands \newif\ifwhole \wholefalse. \newif is a TeX primitive. What it does is kind of complicated: It takes one argument, which should be of the form \iffoo. In this case it is \ifwhole (we could also have written this as \newif {\ifwhole}). So, when \newif\iffoo is run, the result is that three new commands are being defined. Two of these commands are \footrue and \foofalse, and they just set some "magical variable" to true or false respectively. The third new command is the command \iffoo, which is an "if" command an returns true or false depending on whether \footrue or \foofalse is the last command executed.
In out case, after the triple \ifwhole,\wholetrue,\wholefalse has been defined, our program runs \wholefalse. So this means that when \ifwhole gets called in the next line, it will return true.
Ok, let's move to this next line now. TeX "if" clauses have exactly this syntax: \ifclause % stuff that happens when \ifclause is true \else % stuff that happens when \ifclause is false \fi
In our case, \ifwhole is now false, hence the entire \else block gets executed, and we get our header, and later on our footer, hence the document can be compiled.
Now let's see what happens when we are in our master document. Then we again include the header in the same way. Then we have the \renewcommand that redefines the \setflag command to be returning \wholetrue when executed. then we go on to include the various chapters. When header.tex in loaded in them, the \providecommand will not do anything since \setflag has already been defined, hence its definition with \wholetrue is the one that will be used. This now means that the \ifwhole test succeeds, hence the \else part is not executed, so the header data (and similarly the footer data) does not get inserted again (avoiding the disaster that would arise if it did).
Finally, after all the chapters have been included, we redefine the command again to make sure that the footer gets inserted. (I guess you could have directly used \end{document} in the master file instead of trying to include the footer file.)
One little question that might have arisen is why I used \input instead of \include. The reason is that by design (don't ask me why, I don't know) you cannot have nested \include's, while you could have nested \input's. The difference between the \input'ed files and the \include'd files is that the \include'd files generate their own .aux files, while the \input'ed files don't. I am guessing pdfsync might also not work with \input'ed files, but I haven't tested this.
Sorry for the long post, I hope it was interesting to some people.
Haris
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
~~~~~ Christoph Biela
cbiela@gmail.com
On May 23, 2006, at 5:46 AM, Christoph Biela wrote:
That's it thanks!!!
This is a really nice and handy thing. However, somehow this all stopped working and then I only got it working after writing.
\renewcommand{\setflag}{\newif \ifwhole \wholefalse} \setflag % was somehow needed \input{foot.tex}
Hm, I somehow thought I had responded to that. Indeed you need to add the \setflag command, it's a LaTeX thing and a typo on my part. The point is that the footer just checks the variable \ifwhole, and does not do the work that the header does of trying to define \setflag and then calling it. A simpler thing would actually have been:
\wholefalse \input{foot.tex}
instead of the above three lines. All you need is to make sure \ifwhole returns false before entering foot.tex, so that the \else part of foot.tex kicks in. At this point, you don't really need to redefine \setflag.
Does anyone know why? Is this related to TextMate?
Thanks Christoph
Haris
Le 18 mai 06 à 18:00, Christoph Biela a écrit :
It would be great if someone could help me or send the website where this is already posted. However, I would also appreciate some helpful comments on how to write the script by myself.
Hello
I'm not sure that my answer is right for your question because i've some difficulties with english language...
example of personal project:
\documentclass[]{prof} \begin{document} \input{part1.tex} \newline \input{part2.tex} \end{document}
With my personal class prof.cls, i have a file prof.clg with all the calls to packages. If you used another class and if you need packages, it's possible to modify the script.
If i want to compile only part1.tex, i proceed like this
1) Boulot(/Users/ego/Documents/Boulot) is the folder for all my works and it's declared in texmf.cnf that simplifies the paths.
2) In Boulot I created a directory "temp" for temporary files.
3) Then In the Shell variable I created :
TM_DIR_FOR_TEMP : /Users/ego/Documents/Boulot/temp MY_CLASS : prof
and I used a script with this idea : creation of temporary file : tempfile which contains part1.tex
like this : cat >tempfile.tex<<EOF \documentclass{$MY_CLASS} \thispagestyle{empty} \graphicspath{{$DIRtemp/}} \begin{document} \input $M \end{document} EOF
$M is part1.tex \graphicspath{{$DIRtemp/}} : i put the graphics files always in the same directory of part1.tex
========================================== I don't use latexmkrc !!! so I modified only a part of the original script : Latex & View
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! use this script with precaution !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
========================================== ==========================================
# Source some support functions we need. . "${TM_SUPPORT_PATH}/lib/html.sh"
V=${TM_LATEX_VIEWER:=html}
# Set up some variables we need. TEX=${TM_LATEX_COMPILER:=pdflatex} EL=${TM_LATEX_ERRLVL:=1} M=${TM_LATEX_MASTER:=$TM_FILEPATH} # in M : part1.tex DIRtemp=`dirname "$M"` # the directory of part1.tex
DIR="/Users/ego/Documents/Boulot/temp" FILE="tempfile.tex"
cd ${TM_DIR_FOR_TEMP} cat >tempfile.tex<<EOF \documentclass{$MY_CLASS} \thispagestyle{empty} \graphicspath{{$DIRtemp/}} \begin{document} \input $M \end{document} EOF
# Switch to the right directory. cd "$TM_PROJECT_DIRECTORY" cd "$DIR"
# Prepare output window. htmlHeader "Compiling LaTeX (file $FILE)" echo '<h1>Compiling LaTeX...</h1>'
run_tex () { if [ "$TEX" != latexmk.pl ] then "$TEX" ${TM_LATEX_OPTIONS:=-interaction=nonstopmode -file-line- error-style} tempfile.tex else "$TEX" -f -r "${TM_BUNDLE_SUPPORT}/latexmkrc" "$1" fi }
# Compile. run_tex "$FILE" 2>&1| latexErrWarnHtml.py -v RC=$?
if [ "$V" == html ]; then if [ -s "${PDF}" -a "$PDF" -nt "$FILE" ]; then WEB_LOC="tm-file://${DIR}/${PDF}" WEB_LOC="${WEB_LOC//\#/%23}" if (($RC > $EL)); then link "${WEB_LOC}" 'Click Here to Preview' else redirect "${WEB_LOC}" fi else strong "Error: PDF file not written to disk" fi htmlFooter else open -a "$V" tempfile.pdf if (($RC <= $EL)); then closeWindow; fi fi echo "Cleaning..." # Switch to the right directory.
cd ${TM_DIR_FOR_TEMP} rm -f tempfile.aux rm -f tempfile.log echo "Done Cleaning up" ========================================== ==========================================
Greetings
Alain Matthes
Perhaps there is a better way of also doing this if you can improve this script, I will be very happyU