How to run a batch file to compile a tex file that calls txt files in itself?
You need to be more specific about what you are doing. The batch line you have in your comment will not work, but will not yield the error you cite. On my system, latex *.tex
will result in ! I can't find file '*.tex'.
Try to modify your batch file to use for
:
@echo off
for %%f in (*.tex) do (
latex "%%f" && dvips "%%~nf.dvi" && ps2pdf "%%~nf.ps"
)
pause
Or simpler (if you do not rely on PostScript features):
@echo off
for %%f in (*.tex) do (
pdflatex "%%f"
)
pause
Including data from external text files should not matter.
Edit: The above batch files works on my system with a document like
\documentclass{article}
\usepackage{pgfplotstable}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.txt}
x;y
0;0
1;1
2;4
3;9
\end{filecontents*}
\begin{document}
\section{Input of raw data}
\begingroup
\obeylines
\noindent
\input{\jobname.txt}%
\endgroup
\section{Typeset data with \texttt{\string\pgfplotstabletypeset}}
\pgfplotstabletypeset[col sep=semicolon]{\jobname.txt}
\end{document}
If it works differently on your system you need to provide an example document showing the problem.
End of edit
Additionally, when using batch files you need to manually take care of the clean-up and recompilation for proper ToC and references, etc. You should look into tools for automizing these tasks such as texify
or Arara and similar tools.
Related videos on Youtube
Rebecca Jones
Updated on August 01, 2022Comments
-
Rebecca Jones over 1 year
Trying to make a batch file that compiles a .tex document that calls .txt files into it.
Can get the batch file to compile the .tex doc, brings back errors when trying to find each .txt file. Each .txt file is in the same folder as the .tex document.
Any help is appreciated.
My .bat file is;
latex C:\Users\RJones\Documents\LaTeX\Work\Notes\SPPProcNotes.tex dvips C:\Users\RJones\Documents\LaTeX\Work\Notes\SPPProcNotes.tex ps2pdf C:\Users\RJones\Documents\LaTeX\Work\Notes\SPPProcNotes.ps C:\Users\RJones\Documents\LaTeX\Work\Notes\SPPProcNotes.pdf pause
-
cmhughes almost 8 yearsWelcome to the site! Could you clarify a little what you mean by calls .txt files into it? for example, do you mean '\include{myfie.txt}'?
-
Rebecca Jones almost 8 yearsI'm using \pgfplotstable to insert the txt file. When compiling it with TeXworks it all works perfectly, but I want to be able to compile it without people seeing (and changing) the .tex code, I'm struggling to get this to work. Is it possible to make a .bat file to compile the .tex doc with .txt files in it?
-
touhami almost 8 yearsif the file compile without error from texworks it will be fine if compiled with batch file.
-
Rebecca Jones almost 8 yearsmy batch file is ; " latex *.tex dvips *.tex ps2pdf *.ps *.pdf pause " * is the file path. Sorry I'm not used to running it like this so I have no idea what's not working!
-
touhami almost 8 yearstry add
pause
in the end of you.bat
to see what happen if latex is an unknown command you need to add your compiler path for example:path=C:/programmes/miktex/bin;%path%
-
Rebecca Jones almost 8 yearsIt starts to compile then I get the error, "! Package pgfplots Error : Could not read table file 'IDs.txt' " . As it can find the 'IDs.txt' file when I run in TeXworks I don't know what I'm doing wrong with the .bat file?
-
daleif almost 8 years@RebeccaJones is the
.tex
and.txt
files in the same folder? -
Rebecca Jones almost 8 years@daleif yes the files are all in the same folder. It can find them when compiling with TeXworks but not when I try with a .bat file so not sure where I'm going wrong with it!
-
daleif almost 8 years@RebeccaJones how about posting exactly what your bat file looks like right now (update the question). As Martin mentions: LaTeX cannot handle
*
. Also have you tested compiling your file directly from the command prompt actually works -
Rebecca Jones almost 8 years@daleif Added what my .bat file is exactly (sorry if it's bad layout!)
-
daleif almost 8 yearsWhere us the
.bat
in relation to the.tex
? My guess is that the current folder as see from then.bat
is not the same as the.tex
file (as indicated by you using a full path). Then when LaTeX gets to the point where it is asked to readfil.txt
that file will be looked for in a completely different folder than where the.tex
is. Usually it is recommended tocd
to the folder where the.tex
is, and then run there. That is more or less whatTeXworks
does. -
Martin Heller almost 8 years@RebeccaJones change to the directory of your documents first using
cd
orpushd/popd
and then compile the document without supplying the full path.dvips
should be fed thedvi
file, not thetex
file. -
Rebecca Jones almost 8 years@daleif thank you! I had the .bat file running in the folder above the .tex and .txt files. Using the code from Martin Heller (see below) and running it from the same folder worked perfectly for me!
-
-
Rebecca Jones almost 8 yearsThank you for your answer! It gives me the same error though, I feel like I'm doing something fundamentally wrong somewhere. I have no prior knowledge of .bat files so sorry if I'm missing anything painfully obvious! I just want to compile my .tex file automatically without opening it yourself each time. The first error the .bat file returns with is that it can't find the external text file which confuses me
-
Martin Heller almost 8 years@RebeccaJones Please provide the batch file and a minimal document that result in an error on your system.
-
Rebecca Jones almost 8 yearsthank you for the help, your .bat file worked for me after I put it into the same folder as the .tex and .txt file! I had the .bat file in the folder above it. Sorry for being silly!