gpoore / pythontex

A LaTeX package that executes Python and other code in LaTeX documents, and includes the output
879 stars 99 forks source link

Enhancement: when running latex log when calling pythontex is necessary #166

Open Reissner opened 4 years ago

Reissner commented 4 years ago

pythontex works as bibtex, makeindex, makeglossaries: invoke latex, then the tool then latex again. All these tools give indication that sth is wrong with output pdf indicating that rerun is required.

I feel, should be the same with pythontex

gpoore commented 4 years ago

The LaTeX part of pythontex does provide a warning in some cases when things need to be rerun. Such warnings can probably be improved in the future. However, in the general case, it is not possible to determine whether pythontex needs to run without running pythontex. That would require translating all of pythontex's code management and dependency tracking from Python into LaTeX, which isn't really practical.

If there is a specific situation you are having issues with, it might be possible to address that, even though the general case is difficult. Or you might look into using latexmk for managing document builds. It has some support for pythontex.

Reissner commented 2 months ago

I found out, situation is a bit different: One has to distinguish: If the pytxcode file changes, then it is likely that pythontex must be called again followed by latex. In particular, if after running latex the pytxcode occurs, this counts as a change.

One may wonder whether the pytxcode may change because of a subsequent run of *latex. This happens at least if code is in the caption of a float which is not that unusual.

To display a warning in that case, rerunfilecheck may be used in a similar way as done in package hyperref with out files. The only difference is, that not just latex must be rerun, but pythontex followed by latex.

Another similar case is the biblatex package combined with biber. running latex on a TEX file with biblatex package creates a file with extension bcf, as running latex on a TEX file with pythontex package creates a file with extension pytxcode.

It would be nice to notify the user that (s)he shall run pythontex followed by *latex.

If biblatex is configured to include backreferences, running latex may change the bcf file forcing biber and latex to run again. Fortunately, biblatex emits an according warning then.

Accordingly, if code is in captions of floating objects, running latex may change the pytxcode file . It would be very advantageous if pythontex would emit a warning, that rerun of pythontex followed by latex is required. forcing pythontex and *latex to run again. If the bibliography has back references, then running

Reissner commented 2 months ago

Also the manual shall be updated: it shall be mentioned that placing code in captions of floating objects may change the pytxcode file and requires according rerun. Note that the first change in the pytxcode comes from the fact, that the code for captions occur only in the second run. But even afte a change is possible; if the floating objects change their position which changes execution order of the code.