For tests/exams, it is common to compile two versions of the same .tex file, one with only questions and one with both questions and answers. Inside the .tex file, the answers are shown if there is some \def\showanswers{}
defined, i.e. it does \ifdefined\showanswers{answer here}\fi
. Adding/commenting the \def
and compiling each time is annoying.
In TexStudio, I defined a user command to do this nicely:
pdflatex --synctex=1 --interaction=nonstopmode -job-name="?m)-answers" "\def\showanswers{}\input{?m.tex}"
Which works just fine and produces <file>-answers.pdf
. However, I'd like my command to also launch the internal viewer for <file>-answers.pdf
but it seems that the internal viewer always opens <file>.pdf
Adding the file name as argument to txs:///view-pdf-internal
doesn't work:
txs:///userAnswers pdflatex --synctex=1 --interaction=nonstopmode -job-name="?m)-answers" "\def\showanswers{}\input{?m.tex}" | txs:///view-pdf-internal -- embedded "?m)-answers.pdf"
The above fails. Any way around it? If not, could you add this in a future release?
Anonymous
p.s. I'd like to use the internal viewer for its seamless forward and inverse search capabilities. I imagine that some extra arguments are needed to make fwd and inv search work when the pdf file name differs from the tex file name.
Ticket moved from /p/texstudio/bugs/1192/
implemented: hg 4895 (95ba29d23074)
I just tried v2.8.9 hg 4901 snapshot for Windows and this sometimes it works sometimes it fails, the viewer says:
Failed to find file "compsci-answers.pdf"; perhaps it has been deleted.
But the pdf file exists and is valid. This seems to depend on the file name.
Specifically:
If the .tex file is
compsci-4.tex
then it works and the viewer displayscompsci-4-answers.pdf
just fine.But if it's called just
compsci.tex
then it compilescompsci-answers.pdf
just fine but I get the above error in the internal viewer. It seems the internal viewer gets confused but not always ... odd.My user defined commands are as follows:
userCompAns:Compile version with answers
pdflatex --synctex=1 --interaction=nonstopmode -job-name="?m)-answers" "\def\showanswers{}\input{?m.tex}"
userViewAns:View version with answers
txs:///view-pdf-internal --no-focus "?m)-answers.pdf"
I execute the first and then the second (or both as txs:///userCompAns | txs:///userViewAns).
Further to my bug report just above: if I use
"?am)-answers.pdf"
instead of"?m)-answers.pdf"
(note the extra "a" which prepends the full path) then it works forcompsci.tex
as well. I haven't tested other file names yet.Not really, if the filename is not absulute we look for it in all paths specified in
Options -> Build -> Build Options -> Additional Search Paths -> PDF Files
. Maybe that's what you've seen.hg 4942 (f41a53a915aa) modifies the search to include the directory of the main file as well. With that, also
?m)
is working as well.The best would be to search in the .tex file's folder first, then others.
Not sure that's what I was seeing. The above odd behavior happened even with file names that didn't exist anywhere else, i.e. they all compiled fine but not all were displayed by the viewer; changing the tex file name made it work.
Anyway, I'm now playing it safe and use
?am)
.Thanks for being on top of things.
That's what we do now.
Great. Now that this feature is working, including forward and backward search (which is truly awesome), you could include 2-3 commands by default as user defined commands to do this questions and answers thing, and make a note about it in the list of features and manual ... lecturers and examiners would love you :)
Thanks for all the work on Texstudio!
Can I donate for the project anywhere? If not, you could add a Paypal button on the website.