2

The compilation works fine if I use LaTeX, Python, and then LaTeX, with the command for Python :

python  "C:\Program Files (x86)\MiKTeX 2.9\scripts\pythontex\pythontex.py" 

But I can't use latexmk to make the same thing :

If I try:

latexmk  -r C:\latexmk\LatexMk.txt  essai.tex

with in the file LatexMk.txt:

add_cus_dep('pytxcode', 'tex', 0, 'pythontex');
sub pythontex { return system("pythontex \"$_[0]\""); }
$aux_dir = 'auxiliaire2';
$pdflatex = 'pdflatex-synctex=1 --shell-escape %O %S';
$latex = 'latex -synctex=1 --shell-escape %O %S';

then LaTeX compiles fine, but when PythonTeX runs, an arror occurs:

Package PythonTeX Warning: Non-existent Pygments content on input line 11.

and I obtain as result

??PythonTex??

I don't understand why. I'm using Windows 10.

More precisely, essai.tex is:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{pythontex}
\begin{document}
Here's the code in the document
\begin{pyverbatim}
        return '\\SI{' + str(var) + '}{' + unit + '}'
\end{pyverbatim}
\end{document}

and the console's ouput is :

'Custom dependency list:
  pytxcode tex 0 pythontex
Latexmk: This is Latexmk, John Collins, 17 Jan. 2018, version: 4.55.
Rule 'latex': File changes, etc:
   Changed files, or newly in use since previous run(s):
      'E:\professionnel\_BTS_SIO_1_U_22_algo\TD_6\essai.tex'
      'essai.tex'
------------
Run number 1 of rule 'latex'
------------
------------
Running 'latex -synctex=1 --shell-escape  -recorder -aux- 
directory="auxiliaire2"  
"E:\professionnel\_BTS_SIO_1_U_22_algo\TD_6\essai.tex"'
------------
Latexmk: applying rule 'latex'...
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (MiKTeX 2.9.6630 64-bit)
entering extended mode
(E:/professionnel/_BTS_SIO_1_U_22_algo/TD_6/essai.tex
LaTeX2e <2017-04-15>
Babel <3.18> and hyphenation patterns for 75 language(s) loaded.

Comment from me : I cut lines where Miktex works...

No file pythontex-files-essai/essai.pytxmcr.
Run PythonTeX to create it.

Package PythonTeX Warning: Non-existent Pygments content on input line 11.

[1] (E:\professionnel\_BTS_SIO_1_U_22_algo\TD_6\auxiliaire2\essai.aux) )
Output written on essai.dvi (1 page, 480 bytes).
SyncTeX written on essai.synctex.gz.
Transcript written on 
E:\professionnel\_BTS_SIO_1_U_22_algo\TD_6\auxiliaire2\es
sai.log.
===========Latexmk: Missing input file: 'pythontex-files- 

essai/essai.pytxmcr' from line 'No file pythontex-files-essai/essai.pytxmcr.' Latexmk: Missing input file: 'pythontex-files-essai/essai.pytxmcr' from line 'No file pythontex-files-essai/essai.pytxmcr.' Latexmk: Log file says output to 'essai.dvi' === TeX engine is 'pdfTeX' Latexmk: All targets (essai.dvi) are up-to-date'

Xavier ANSIAUX
  • 107
  • 1
  • 8
  • If I use add_cus_dep('pytxcode', 'tex', 0, 'pytxcode2tex'); sub pytxcode2tex { return system("pythontex \"$_[0]\""); } I have no problem. Note: there is an added space between the pythontex and the \" in the rule. – Herb Schulz Mar 17 '18 at 20:27
  • Thanks for your comment.With an added space as you said : same result. – Xavier ANSIAUX Mar 17 '18 at 21:12
  • The console's output seems linked to the missing of pygments for python : Run PythonTeX to create it. Package PythonTeX Warning: Non-existent Pygments content on input line 11. – Xavier ANSIAUX Mar 17 '18 at 21:14
  • but Pygments is installed . – Xavier ANSIAUX Mar 17 '18 at 21:16
  • I think that Miktex chose a Python's installation in my PC wich hasn't Pygments installed. But where is it? Where can I change Python's installation? – Xavier ANSIAUX Mar 18 '18 at 09:14
  • perhaps use Anaconda for a comprehensive Python distribution. But I don't know about Windows. –  Mar 18 '18 at 09:28
  • @jfbu Thanks you! I installed Anaconda , uninstalled Miktex 64 bits, and installed Miktex 32bits : I obtained the same result. – Xavier ANSIAUX Mar 19 '18 at 11:07
  • to avoid the missing pygments error, I changed pythontex to pythontex3 in .latexmkrc file; might help someone. – jackw11111 Jul 17 '18 at 01:50

1 Answers1

0

The problem is discussed in https://github.com/gpoore/pythontex/issues/132#issuecomment-492531792 .

With your configuration, after the first time where you manually run pythontex, subsequent runs with latexmk should work automatically.

That having said, if you want to make it work in the first run as well, the linked GitHub issue above has a solution -- put the following in latexmkrc:

# Support for pythontex in v. 0.16 or higher, with latexmk 4.62 or higher
#
# What these definitions provide/do:
# 1. Variable specifying command string for invoking pythontex
# 2. Addition to %extra_rule_spec of template for pythontex rule. This
#    tells latexmkrc to create the rule when it is initializing for
#    processing a TeX file.
# 3. A subroutine mypythontex that the pythontex rule is defined to
#    call. This runs pythontex and then sets dependency information.
# 4. Settings for the files generated by the pythontex package and the
#    pythontex program so that the files are deleted in a clean-up
#    operation.

$clean_ext .= " pythontex-files-%R/* pythontex-files-%R"; push @generated_exts, 'pytxcode';

$pythontex = 'pythontex %O %S'; $extra_rule_spec{'pythontex'} = [ 'internal', '', 'mypythontex', "%Y%R.pytxcode", "%Ypythontex-files-%R/%R.pytxmcr", "%R", 1 ];

sub mypythontex { my $result_dir = $aux_dir1."pythontex-files-$$Pbase"; my $ret = Run_subst( $pythontex, 2 ); rdb_add_generated( glob "$result_dir/*" ); open( my $fh, "<", $$Pdest ); if ($fh) { while (<$fh>) { if ( /^%PythonTeX dependency:\s+'([^']+)';/ ) { print "Found pythontex dependency '$1'\n"; rdb_ensure_file( $rule, $aux_dir1.$1 ); } } undef $fh; } else { warn "mypythontex: I could not read '$$Pdest'\n", " to check dependencies\n"; } return $ret; }

As far as I can see, the normal add_cus_dep cannot be used to "properly" handle this because the location of the source file a.pytxcode is different from that of the target file pythontex-files-a/a.pytxmcr.

I unfortunately can't find documentation of %extra_rule_spec. (latexmk with pythontex, lualatex and long name not working may have some explanation.)


An alternative method is to use the other method explained in pythontex manual:

pythontex manual

The method was originally made for the case where --output-directory is not the normal one, however it doesn't really matter -- it allows add_cus_dep to work properly by moving the a.pytxmcr to the current directory, however the disadvantage, as mentioned, is the other auxiliary files (a.pytxpyg, pythontex_data.pkl) is also moved to the current directory.

user202729
  • 7,143