0

This might be an XY-problem, but I'm trying to compile two PDFs from the same source. One containing exercises, called a.pdf, and another which additionally includes the answers, called a-solutions.pdf.

I'm using TexStudio on Windows and have succeeded in creating the two files using the following configuration for pdflatex (simplified for the sake of the example):

pdflatex.exe "\newif\ifsolutions\solutionsfalse\input{%.tex}" | pdflatex.exe "\newif\ifsolutions\solutionstrue\input{%.tex}" --jobname=%-solutions

Basically, I'm running pdflatex twice, once with a boolean variable (solutions) set to false, and a second time with the variable set to true.

However, I'm not able to resolve the bibliography references for the second file. I don't know how to create the necessary a-solutions.bbl file required for the second (and third) pass of pdflatex.

Here's my current bibtex configuration in TexStudio:

bibtex.exe % | bibtex.exe %-solutions.aux

Again, I'm trying to run things twice: once for a.pdf and once for a-solutions.pdf. However, only a.bbl is created. How can I also create a-solutions.bbl?

Is it even possible to solve this?

Note: Ideally I want a solution that only requires modification to my TexStudio configuration and/or my source files. That is, I do not want to rely on external tools or build scripts.

hakoja
  • 325
  • Why does it actually fail? When I do pdflatex --jobname XXX, then this will generate XXX.aux, and then bibtex XXX will generate XXX.bbl, which will be used when doing again pdflatex --jobname XXX. – gernot Sep 05 '21 at 12:36
  • Unrelated: A solution different from using a switch is to control the behavior (with/without solutions) via the jobname, see https://tex.stackexchange.com/q/197330. So you would either make a copy of the file to something ending with solutions, or you would use the option --jobname as you already do. The difference is that you don't need the switch \ifsolutions. BTW, the option --shell-escape is unrelated to your question. – gernot Sep 05 '21 at 12:42
  • @gernot Hmm, maybe I don't understand how the bibtex command works, but when I run it (through TexStudio), it doesn't seem to pick up on the a-solutions.aux file created in the previous run of pdflatex. Thus, it only creates a.bbl, but not a-solutions.bbl. So is bibtex %-solutions.aux the right command to tell bibtex to "use this aux file, and spit out a bbl file with a matching name"? – hakoja Sep 05 '21 at 13:33
  • @gernot Regarding `--shell-escape': thanks, removed! – hakoja Sep 05 '21 at 13:33
  • @gernot You were right! It turns out that bibtex %-solutions**.aux** was in fact the wrong command, and simply removing the .aux extension fixed the problem. If you want to write this up as an answer I'll happily accept. Else I'll just do it myself in a little while. Thanks! – hakoja Sep 06 '21 at 05:55
  • Gz for solving the problem! May I suggest that you write the answer yourself, with all details that are relevant to the problem? In fact, under Linux, bibtex XXX.aux works as well, so it must be specific to Windows, or TeXstudio, or both. As I don't work in your environment, I wouldn't be able to test my answer. Moreover, in the end you solved your problem yourself, after discussing it with me. – gernot Sep 06 '21 at 08:28

1 Answers1

0

The general approach taken in the question is sound, but bibtex on Windows does not want the input to include the .aux extension. Removing this resolved the question.

For completeness, here's a MWE that compiles to two different pdfs (only tested with TexStudio on Windows). This solutions also incorporates the suggestion proposed by @gernot.

a.tex

\documentclass{article}

\usepackage{substr} \IfSubStringInString{\detokenize{solutions}}{\jobname} {\def\solutions{true}} {\def\solutions{false}}% \usepackage[solutions=\solutions]{exframe}

\begin{document}

\begin{problem} Test \cite{ref1}. \end{problem}

\begin{solution} Solution \cite{ref2}. \end{solution}

\bibliographystyle{plain} \bibliography{refs} \end{document}

refs.bib

@misc{ref1,
author = {A},
title = {Ref 1.},
year = {}
}

@misc{ref2, author = {B}, title = {Ref 2.}, year = {} }

To compile (on TexStudio/Windows):

pdflatex

pdflatex.exe %.tex | pdflatex.exe %.tex --jobname=%-solutions

bibtex

bibtex.exe % | bibtex.exe %-solutions
hakoja
  • 325