0

I am running into a problem where Texstudio is only running the first command of a list of commands, and I am wondering if I am doing something wrong. Here is a minimal working example so you can see what I mean.

Minimal working example

First I will configure texstudio so it produces the error, then I will go through the steps to produce the strange behavior.

Configuring texstudio

Create a new folder test and create a file test.tex with contents

\documentclass{article}
\begin{document}
test
\end{document}

Now open test.tex with texstudio, and in the texstudio menu, go to options>configure texstudio..., click on the commands tab in the left pane, and change the command for PdfLatex (the second in the list of commands for me) to

ls | pdflatex -synctex=1 -interaction=nonstopmode %.tex

This command is different from the default texstudio's default pdflatex command because of the addition of ls |. Of course ls is the usual thing you type into a terminal. It serves no purpose here other than to be a dummy command. | is used to seperate multiple commands if you have a list of commands you want to run, as desribed here in the third sentence of the second paragraph.

To test that everything is configured properly, in the texstudio menu, go to Tools>Commands>PDFLaTeX. On my system, the file compiles as usual, and you get the expected output. In the message output, you should see

Process started: ls

Process exited normally

Process started: pdflatex -synctex=1 -interaction=nonstopmode "texTemplate".tex

Process exited normally

You see that there are two processes: one for ls and one for pdflatex

Producing the strange behavior

Now that everything is configured, we are ready to produce the strange behavior. The first step here exhibits normal behavior but is necessary to produce the strange behavior. In test.tex, change "test" to "te\st", so that text.tex now looks like

\documentclass{article}
\begin{document}
te\st
\end{document}

As you did in the configuration section, run Tools>Commands>PDFLaTeX. This time the source file contains an error, so we expected Texstudio to tell us about the error, and indeed this is what happens, so there is nothing strange here. From "messages" in texstudio, we see

Process started: ls

Process exited normally

Process started: pdflatex -synctex=1 -interaction=nonstopmode "texTemplate".tex

Process exited with error(s)

Now, go and revert text.tex back to its orginal contents (that is, change "te\st" back to "test"). Then, run Tools>Commands>PDFLaTeX. Now things get interesting. It shows us the log as if we did not change back to "test". Looking at "messages" in textstudio, we see why texstudio does this. The "messages" output is

Process started: ls

Process exited normally

Only ls run. pdflatex never ran, so the log file never changed. Now, certainly you can compile the file with texstudio if you erase all the files except for test.tex and then restart texstudio. In fact, it is only necessary to delete the log file and restart texstudio.

So my question is, how is it possible to have texstudio run all the commands regardless if there are errors in the source file? Am I doing something wrong or is this a bug with texstudio.

2
  • 1
    I will write up some of what I know in an answer. Mar 23, 2017 at 16:13
  • I didn't see this already reported a as bug, so I created a ticket here. We will see what happens. Mar 23, 2017 at 16:49

2 Answers 2

3

You've setup the build system in a way that is a grey area where the behavior is not guaranteed: The commands on the command panel should only be single build system commands. Note that | chains build system command (see the manual).

Background: Why does it fail?

txs:///pdflatex is internally marked as a compilation command, i.e. it checks for errors in the log file and stops if there are any. For technical reasons, this is performed on every subcommand (which we expect only to be one, namely the pdflatex call). In your case, once you have an error in your log an run ls, the compilation is aborted and you never get to a new pdflatex call to update the log.

What you should do:

You have several ways to fix the configuration:

  • do not chain the commands in TeXstudio, but in the shell: sh -c "ls & pdflatex ...", or put all the commands in a shell script and call this.
  • Chain the commands in the build system (page "Build") by creating a user command:

enter image description here

The both variants differ slightly in the behavior for automatic recompilation: TXS checks if the log contains information that a rerun is necessary and then runs pdflatex again (configurable in Build -> Build Options, enabled by default). While first case runs ls with every rerun, i.e. ls pdflatex ls pdflatex ..., the second case runs ls only once ls pdflatex pdflatex.

  • Depending on what you actually want to do with the placeholder ls, there are also other variants, e.g. Build -> Meta Commands -> Precompile. Which is run only once per build (Note that compile is run twice in case of a bibliography: compile bibliography compile).
5
  • Thanks. So if I understand right, chaining of commands in the commands team of the txs configuration isn't supported; you are only supposed to chain commands in the build section. I was confused because in the documentation, it says, "Every txs-command is a list of external programs/latex-commands and other txs-commands to call." I assumed by "every", they meant even the commands in the command tab. Maybe this could be clarified in the documentation? I will try it your suggestion when I get home. Apr 17, 2017 at 2:22
  • Ok I tested it out and this works for me. In my actual situation, I was using the latexmk command as my compile command, and I had my latexmk command set to ls|mkdir -p auxiliaryFiles|latexmk -pdf -silent -jobname=auxiliaryFiles/%Build -pdflatex="pdflatex -interaction=nonstopmode -synctex=1 %%O %%S" %|ln -fs auxiliaryFiles/%Build.pdf %.pdf|ln -f auxiliaryFiles/%Build.log auxiliaryFiles/%.log. Now I have the latexmk comand set to just the actual latexmk part; I put the mkdir command in the precompile command; I have a custom command "makelinks" which is ... Apr 17, 2017 at 15:52
  • ln -fs auxiliaryFiles/%Build.pdf %.pdf | ln -f auxiliaryFiles/%Build.log auxiliaryFiles/%.log; and I have a custom command "customlatexmk" which is txs:///latexmk | txs:///makelinks; and my default compile is just this customlatexmk command. Everything works how I want it to. So thanks. Apr 17, 2017 at 15:54
  • @NowIGetToLearnWhatAHeadIs I think no-one had really considered the problems that may arise from mutliple parts in a compiler command until now. Therefore the code and the doc was "every". I've already updated the code and doc in the development branch. Future versions will show a warning and the doc is clarified. Apr 17, 2017 at 22:37
  • I am having problems with chaining pythonTex commands through TexStudio, and I think this is the culprit. The sequence of commands works fine in the shell, but not as a user command: txs:///pdflatex | pythontex %.tex | txs:///pdflatex | txs:///view-pdf-internal --embedded. So this option to chain the commands is not always succesful.
    – Colin
    Mar 9, 2020 at 0:16
1

The behavior can be avoided by removing the spaces around |. Then the command becomes

ls|pdflatex -synctex=1 -interaction=nonstopmode %.tex

However, this solution is limited: it does not work if the first command has spaces in it (for example, a command with flags such as ls -l). In this case you can prepend ls to your list of commands and you will get correct behavior. So, for example, the following doesn't work

ls -l|pdflatex -synctex=1 -interaction=nonstopmode %.tex

but the following does, and it achieves the same thing

ls|ls -l|pdflatex -synctex=1 -interaction=nonstopmode %.tex

(notice the fact that the first command is ls is not related to the second command being ls. In an actual application the first command will always be ls (or any other "NOP" command as long as it doesn't have spaces), but the second command will be whatever command is needed for your application, such as creating a directory or moving files or linking files.)

As to whether anything is being done wrong in the question, I am not sure, but I would guess that the behavior is a result of a bug in texstudio, especially considering that prepending ls to the list of commands somehow fixes the problem.

You must log in to answer this question.

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