Conversion ToolsChanging the default build directory

Information and discussion about output converters related to LaTeX (e.g. dvips, ps2pdf, ...)
erwann
Posts: 75
Joined: Thu Aug 25, 2016 2:24 am

Changing the default build directory

Post by erwann »

Reminder (this works):

Code: Select all

$ pdflatex --output-dir ~/_build foo.tex
How can I make the specified directory the default build directory? This did not do it:

Code: Select all

$ export TEXMFOUTPUT="~/_build"
$ echo $TEXMFOUTPUT
~/_build
$ pdflatex foo.tex
Relevant excerpt from the man page.
Last edited by erwann on Fri Sep 16, 2016 8:28 pm, edited 1 time in total.
x_86 / Linux Mint 18.3 / texlive 2015.20160320-1ubuntu0.1 / TeXworks 0.5r1361 (Debian)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

Changing the default build directory

Post by Stefan Kottwitz »

You can also run this check:

kpsewhich -var-value="TEXMFOUTPUT"

Stefan
LaTeX.org admin
erwann
Posts: 75
Joined: Thu Aug 25, 2016 2:24 am

Changing the default build directory

Post by erwann »

Here's the output of the suggested check:

Code: Select all

$ kpsewhich -var-value="TEXMFOUTPUT"
/Users/my-mac/_build
Again, TEXMFOUTPUT is ignored by pdflatex, or is meant for a different purpose.
x_86 / Linux Mint 18.3 / texlive 2015.20160320-1ubuntu0.1 / TeXworks 0.5r1361 (Debian)
erwann
Posts: 75
Joined: Thu Aug 25, 2016 2:24 am

Re: Changing the default build directory

Post by erwann »

Any more thoughts on this?
x_86 / Linux Mint 18.3 / texlive 2015.20160320-1ubuntu0.1 / TeXworks 0.5r1361 (Debian)
rais
Posts: 419
Joined: Sun Nov 16, 2014 8:51 pm

Changing the default build directory

Post by rais »

Well, the way I read your man page's excerpt, this $TEXMFOUTPUT is considered, iff[1] the current directory isn't writable.
You could verify that by making the current folder read-only, prior to running pdfLaTeX.
OTOH, it might be easier to use an alias, as in

Code: Select all

alias mypdflatex='pdflatex --output-dir ~/_build'
and then just use this alias instead of the original, say

Code: Select all

mypdflatex foo
(untested, though: I'm sitting in a hotel without my trusty PC...then again, I'm not so sure I would've tested it, even if I were at home at my trusty PC---I don't see any code here to run it on, i.e., the `foo.tex' is missing)

[1] iff: if, and only if

KR
Rainer
erwann
Posts: 75
Joined: Thu Aug 25, 2016 2:24 am

Changing the default build directory

Post by erwann »

rais wrote:OTOH, it might be easier to use an alias, as in
Indeed:
#!/bin/bash
# DESCRIPTION: tools for changing pdflatex's default build directory
# RE: http://latex-community.org/forum/viewto ... 52&t=28499
#
# INSTALL :
# copy to a directory in $PATH
# $ chmod 755 thisfile.sh
#
# USAGE:
# $ source thisfile.sh
# $ eval "ls *.?($TEXBUILDEXT)" # Lists TeX build files in the current dir
# $ rmtexbuild # Removes TeX build files from the current dir
# $ pdflatexredirect foo.tex # Writes to ~/_build
#
# TESTED OK UNDER:
# - GNU bash, version 4.3.46(1)-release (x86_64-apple-darwin15.5.0)

export TEXBUILDEXT='log|dvi|out|pdf|aux|blg|bbl'; #anything else?
shopt -s extglob;
alias rmtexbuild='eval "rm *.?($TEXBUILDEXT)"';
alias pdflatexredirect='pdflatex --output-dir ~/_build';
x_86 / Linux Mint 18.3 / texlive 2015.20160320-1ubuntu0.1 / TeXworks 0.5r1361 (Debian)
rais
Posts: 419
Joined: Sun Nov 16, 2014 8:51 pm

Changing the default build directory

Post by rais »

erwann wrote:
export TEXBUILDEXT='log|dvi|out|pdf|aux|blg|bbl'; #anything else?
that depends on your workflow.
Of the top of my head, I'd add
bcf (biber control file)
glg (glossaries log file)
glo (glossaries file)
gls (glossaries file)
idx (index file, input for makeindex)
ilg (index log file)
ind (index file, output from makeindex)
lof (list of figures)
lot (list of tables)
mt* (minitoc helper files)
nlg (nomenclature log file, if -t option to makeindex was used accordingly)
nlo (nomenclature file)
nls (nomenclature file)
ps (post script file, used to be an in-between dvi and pdf)
toc (table of contents)
and a few more I may remember, if I put my head a bit sideways, such that enough brain mass can concentrate in one corner :mrgreen:

Speaking of glossaries, you may have to parse the tex file to see what kind of extensions will be useed.

Anyway, this
erwann wrote:
alias rmtexbuild='eval "rm *.?($TEXBUILDEXT)"';
looks suspiciously like ``remove everything from the current folder with the extension of <list according to $TEXBUILDEXT>''
Don't you think there may be source files removed by this? E.g., some picture file included by the .tex file via \includegraphics/\includepdf may fail, if you remove all pdf files from the current folder...

KR
Rainer
erwann
Posts: 75
Joined: Thu Aug 25, 2016 2:24 am

Changing the default build directory

Post by erwann »

Don't you think there may be source files removed by this? E.g., some picture file included by the .tex file via \includegraphics/\includepdf may fail, if you remove all pdf files from the current folder...
Feel free to provide a variant of 'rmtexbuild' that takes care of eliminating the "suspicion" your raise by prompting the caller to provide the basename (without the extension) of the files to delete, in this example, 'foo' (or perhaps 'f*', '?(foo|bar)' etc.).
x_86 / Linux Mint 18.3 / texlive 2015.20160320-1ubuntu0.1 / TeXworks 0.5r1361 (Debian)
rais
Posts: 419
Joined: Sun Nov 16, 2014 8:51 pm

Changing the default build directory

Post by rais »

erwann wrote:Feel free to provide a variant of 'rmtexbuild' that takes care of eliminating the "suspicion" your raise by prompting the caller to provide the basename
why should I prompt the caller for something, (s)he should have provided with calling the program in question in the first place?
erwann wrote:(without the extension)
why without? You could give this program a filename (with or without extension), strip off the extension and remove everything matching your pattern. If you allow .tex as the only (possible) extension, you could use that to verify, if this .tex file is even present---before doing anything rash (like removing some files)

Code: Select all

#!/bin/bash
# save as <whatever>.sh, then run make <whatever> and put the resulting <whatever> script somewhere along $PATH
# see http://latex-community.org/forum/viewtopic.php?f=52&t=28499 for the original code, 2016-09-23-rais
# ... and the original hint(s)
#
if [ -z "$1" ]; then
  echo "Usage: $0 file-to-clean-help-files-from[.tex]"
else
  TBRBN=${1%.tex} #the basename of the files-to-be-removed
  if [ -r $TBRBN.tex ]; then # if `source' (the .tex file with same basename as the files-to-be-removed) is readable
    for X in aux bbl bcf blg and-so-on; do
      TBRF=$TBRBN.$X
      test -r $TBRF && rm $TBRF #only try to remove something that's really there
# come to think of it, it might be better to use `echo' before the `rm' in the initial test phase...
    done
  else
    echo "Could not read source file ($SF)---aborting."
  fi
fi
Again, untested, as I'm still travelling without my trusty PC

KR
Rainer
erwann
Posts: 75
Joined: Thu Aug 25, 2016 2:24 am

Changing the default build directory

Post by erwann »

Here's an update that
- Adresses the "looks suspicious" comment here.
- Accomodates bibtex alongside pdflatex.
# INSTALL :
# copy to a directory in $PATH (say ~/bin)
# $ cd ~/bin
# $ chmod 755 thisfile.sh
# $ mkdir ~/_build
#
# USAGE:
# $ source thisfile.sh
# $ echo $TEXTBUILDEXT # Recognize build files' extensions
# $ eval "ls *.?($TEXBUILDEXT)" # Lists TeX build files in the current dir
# $ rmtexbuild foo # Removes foo build files in ~/_build'
# $ rmtexbuildpwd foo # Removes foo build files in curr. dir
# $ pdflatexbuild foo.tex # Writes to ~/_build (*)
# $ bibtexbuild foo.aux # Creates bbl in ~/build (*)
#
# (*) .tex and .aux optional
#
# TESTED OK UNDER:
# - GNU bash, version 4.3.46(1)-release (x86_64-apple-darwin15.5.0)
#
# ALSO SEE:
# http://tex.stackexchange.com/questions/ ... -compiling
#
# TODO:
# Error handling

export TEXBUILDEXT='log|dvi|out|aux|blg|bbl|pdf|bcf|glg|glo|gls|idx|ilg|ind|lof|lot|mt*|nlg|nlo|nls|ps|toc';
shopt -s extglob;
function rmtexbuild(){
eval "rm ~/_build/$1.?($TEXBUILDEXT)";
}
function rmtexbuildpwd(){
eval "rm ./$1.?($TEXBUILDEXT)";
}
function mvtexbuild(){
eval "mv ./$1.?($TEXBUILDEXT) ~/_build/";
}
function mvtexbuildtopwd(){
eval "mv ~/_build/$1.?($TEXBUILDEXT) ./";
}
alias pdflatexbuild='pdflatex --output-dir ~/_build';
function texbuildgeneric(){
rmtexbuildpwd $2;
mvtexbuildtopwd $2;
eval "$1 $2";
mvtexbuild $2;
}
function bibtexbuild(){
texbuildgeneric bibtex "${1%.aux}"
# bibtex ~/_build/$1 not allowed, hence this solution
}
x_86 / Linux Mint 18.3 / texlive 2015.20160320-1ubuntu0.1 / TeXworks 0.5r1361 (Debian)
Post Reply