LaTeX forum ⇒ Conversion ToolsChanging the default build directory Topic is solved

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

Changing the default build directory

Postby erwann » Fri Sep 16, 2016 4:23 am

Reminder (this works):
  1. $ pdflatex --output-dir ~/_build foo.tex


How can I make the specified directory the default build directory? This did not do it:

  1. $ export TEXMFOUTPUT="~/_build"
  2. $ echo $TEXMFOUTPUT
  3. ~/_build
  4. $ 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.
OS X 10.11
pdfTeX 3.14159265-2.6-1.40.17

Tags:

User avatar
Stefan Kottwitz
Site Admin
Posts: 8032
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Fri Sep 16, 2016 11:27 am

You can also run this check:

kpsewhich -var-value="TEXMFOUTPUT"

Stefan
Site admin

erwann
Posts: 18
Joined: Thu Aug 25, 2016 2:24 am

Postby erwann » Fri Sep 16, 2016 8:27 pm

Here's the output of the suggested check:

  1. $ kpsewhich -var-value="TEXMFOUTPUT"
  2. /Users/my-mac/_build


Again, TEXMFOUTPUT is ignored by pdflatex, or is meant for a different purpose.
OS X 10.11
pdfTeX 3.14159265-2.6-1.40.17

erwann
Posts: 18
Joined: Thu Aug 25, 2016 2:24 am

Postby erwann » Mon Sep 19, 2016 11:52 pm

Any more thoughts on this?
OS X 10.11
pdfTeX 3.14159265-2.6-1.40.17

rais
Posts: 114
Joined: Sun Nov 16, 2014 8:51 pm

Postby rais » Tue Sep 20, 2016 8:35 pm

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
  1. alias mypdflatex='pdflatex --output-dir ~/_build'

and then just use this alias instead of the original, say
  1. 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: 18
Joined: Thu Aug 25, 2016 2:24 am

Postby erwann » Wed Sep 21, 2016 2:41 am

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: viewtopic.php?f=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';
OS X 10.11
pdfTeX 3.14159265-2.6-1.40.17

rais
Posts: 114
Joined: Sun Nov 16, 2014 8:51 pm

Postby rais » Wed Sep 21, 2016 8:25 pm

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: 18
Joined: Thu Aug 25, 2016 2:24 am

Postby erwann » Thu Sep 22, 2016 11:10 pm

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.).
OS X 10.11
pdfTeX 3.14159265-2.6-1.40.17

rais
Posts: 114
Joined: Sun Nov 16, 2014 8:51 pm

Postby rais » Fri Sep 23, 2016 9:52 pm

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)
  1. #!/bin/bash
  2. # save as <whatever>.sh, then run make <whatever> and put the resulting <whatever> script somewhere along $PATH
  3. # see http://latex-community.org/forum/viewtopic.php?f=52&t=28499 for the original code, 2016-09-23-rais
  4. # ... and the original hint(s)
  5. #
  6. if [ -z "$1" ]; then
  7. echo "Usage: $0 file-to-clean-help-files-from[.tex]"
  8. else
  9. TBRBN=${1%.tex} #the basename of the files-to-be-removed
  10. if [ -r $TBRBN.tex ]; then # if `source' (the .tex file with same basename as the files-to-be-removed) is readable
  11. for X in aux bbl bcf blg and-so-on; do
  12. TBRF=$TBRBN.$X
  13. test -r $TBRF && rm $TBRF #only try to remove something that's really there
  14. # come to think of it, it might be better to use `echo' before the `rm' in the initial test phase...
  15. done
  16. else
  17. echo "Could not read source file ($SF)---aborting."
  18. fi
  19. fi

Again, untested, as I'm still travelling without my trusty PC

KR
Rainer

erwann
Posts: 18
Joined: Thu Aug 25, 2016 2:24 am

Postby erwann » Tue Sep 27, 2016 6:01 am

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
}
OS X 10.11
pdfTeX 3.14159265-2.6-1.40.17


Return to “Conversion Tools”

Who is online

Users browsing this forum: No registered users and 2 guests