0

I am working with pdflatex on a nested tex file (eg: Main.tex+Chapter1.tex+...) and as my work folder is quite a mess already, I want to have the build files in a subdirectory. Checking the dedicated box in texmaker, hence using the -output-directory option, it works well except for bibtex. I have read the other topics, tried different solutions which weren't working because of the nested files, and finally settled to writing a small bash script that I can call within texmaker.

This works well, bibtex generates the bbl which looks fine, but when running pdflatex afterwards, it looks like there is no bbl at all. I tried placing the bbl in the build directory or in the parent one with the same disappointing results.

Can anyone tell me when and how pdflatex includes the contents of that bbl file, and where it might look for it?

4
  • Related tex.stackexchange.com/q/12686/14757 ?
    – Sigur
    Dec 31, 2014 at 17:00
  • Sigur, the problem is different. The topic from the linked question is finding the aux then the bib files from the build directory, here this step works fine. David, also different problem. I find the aux and bib files, but can make pdflatex use the generated bbl.
    – luneart
    Dec 31, 2014 at 17:03
  • David, the link was not related, but got me on the right track: in the script I need to copy the Main.bbl to Chapter1.bbl, [...] and it works. Thanks a lot!
    – luneart
    Dec 31, 2014 at 17:10

1 Answer 1

2

So, thanks to David it works!

To people who might be in the same situation, here is the bash script:

#!/bin/bash
# This is BibMaker.sh, stupid script for stupidier Bibtex.
#
# Set execute permission first.
# To be used to launch bibtex with a build directory for (Pdf)latex. (-output-directory=<builddir>)
# Within TexMaker, call ./BibMaker.sh <builddir> %

if [ -z "$2" ] # 2 mandatory args: 1 build folder, 2 filename
  then
  echo "Usage: BibMaker.sh <build\ folder> <TeX\ source\ filename> [optional: <unique> xor <chapter> for single or per-chapter bibliography]"
  exit 3
fi
if [ -n "$1" ] # test if config file was provided as arg
  then
  BUILDDIR="$1"
fi

MODE=1
if [ -n "$3" ] # test if 3rd arg: "unique" (default) or "chapter"
  then
#    if [ "$3" = "unique" -o "$3" = "Unique" ]
#      then
#      MODE=1
#    fi
    if [ "$3" = "chapter" -o "$3" = "Chapter" ]
      then
      MODE=2
    fi
  BUILDDIR="$1"
fi

EXITSTATUS=0
cd $BUILDDIR
FILES=`ls | grep ".aux"`

if [ "$MODE" -eq 1 ]
  then
  echo "BibMaker here - mode unique selected."
  OUTPUT=`bibtex $2`
  EXITSTATUS=$?
  echo $OUTPUT
  for file in $FILES
  do
    if [ ! "$2.aux" -ef $file ]
    then cp $2.bbl "${file%.*}.bbl"
    fi;
  done;
fi
if [ "$MODE" -eq 2 ]
  then
  GLOG="$2.blg"
  echo $'\n'"BibMaker here - mode chapter selected." | tee $GLOG
  for file in $FILES
  do
    if [ ! "$2.aux" -ef $file ]
    then
      echo $'\n '"%%%%%%%%%% bibtex ""${file%.*}"" %%%%%%%%%%%"$' \n' >> $GLOG
      OUTPUT=`bibtex "${file%.*}"`
      if [ $? -eq 0 ]
      then
        EXITSTATUS=$?
      fi
      IFS='_'
      echo $OUTPUT | tee -a $GLOG
      unset IFS
    fi;
  done;
fi

cd ..

exit $EXITSTATUS

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .