I am a beginner in Latexmk. Pythontex works fine by typesetting with a shell, but I would like to test also with Latexmk.

I have installed it with TexLive, and I have a lot of rules preinstalled, including /usr/local/texlive/2019/texmf-dist/doc/support/latexmk/example_rcfiles/pythontex-latexmkrc.

When I try to typeset with latexmk -xelatex /Users/jowe_19/Desktop/Finle_Name.tex, the pythontex part does not work.





RULE pythontex preinstalled with Mactex :

# 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 --interpreter python:/Users/jowe_19/opt/miniconda3/bin/python3 %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/*" );
   my $fh = new FileHandle $$Pdest, "r";
   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;


Latexmk: This is Latexmk, John Collins, 18 June 2019, version: 4.65.
Latexmk: applying rule 'xelatex'...
Rule 'xelatex': The following rules & subrules became out-of-date:
Run number 1 of rule 'xelatex'
Running 'xelatex -no-pdf -recorder  "/Users/jowe_19/Desktop/Test_Latexmk.tex"'
This is XeTeX, Version 3.14159265-2.6-0.999991 (TeX Live 2019) (preloaded format=xelatex)
 restricted \write18 enabled.
entering extended mode
LaTeX2e <2019-10-01> patch level 3
Document Class: book 2019/10/25 v1.4k Standard LaTeX document class
))) (/usr/local/texlive/2019/texmf-dist/tex/latex/fontspec/fontspec-xetex.sty
Style option: `fancyvrb' v3.4 <2019/11/09> (tvz)
ode.tex)))) (/usr/local/texlive/2019/texmf-dist/tex/latex/newfloat/newfloat.sty
) (/usr/local/texlive/2019/texmf-dist/tex/latex/currfile/currfile.sty
No file pythontex-files-Test_Latexmk/Test_Latexmk.pytxmcr.
Run PythonTeX to create it.

Package PythonTeX Warning: Non-existent console content on input line 12.

[1] (./Test_Latexmk.aux) )
(see the transcript file for additional information)
Output written on Test_Latexmk.xdv (1 page, 988 bytes).
Transcript written on Test_Latexmk.log.
=== TeX engine is 'XeTeX'
Latexmk: Missing input file: 'pythontex-files-Test_Latexmk/Test_Latexmk.pytxmcr' from line
  'No file pythontex-files-Test_Latexmk/Test_Latexmk.pytxmcr.'
Latexmk: Log file says output to 'Test_Latexmk.xdv'
Latexmk: applying rule 'xdvipdfmx'...
Rule 'xdvipdfmx': File changes, etc:
   Changed files, or newly in use since previous run(s):
   Rule(s) that have been run and require run of dependent rule:
      'xelatex' which requires run of 'xdvipdfmx'
Run number 1 of rule 'xdvipdfmx'
For rule 'xdvipdfmx', running '&do_viewfile(  )' ...
Running 'xdvipdfmx -o "Test_Latexmk.pdf"  "Test_Latexmk.xdv"'
Test_Latexmk.xdv -> Test_Latexmk.pdf
4808 bytes written
Latexmk: All targets () are up-to-date
  • Your example works for me. What exactly doesn't work? – John Collins Dec 24 '19 at 14:55
  • Where do you have python installed. The default version that comes with macOS needs to have packages added to it. I've been using anaconda2 which has everything you could want for science pre-installed. That version of python is installed in ${HOME}/opt/anaconda2/bin on my system so you need to change the line for $pythontex to $pythontex = 'pythontex --interpreter python:${HOME}/opt/anaconda2/bin/python %O %S'; in the latexmkrc file (or platexmkrc if used with the TeXShop latexmk based engines). – Herb Schulz Dec 24 '19 at 15:58
  • @HerbSchulz : Python3 is here /Library/Frameworks/Python.framework/Versions/3.8/bin/python3. Besides, I changed the line $pythontex = ... into $pythontex = 'pythontex --interpreter python:$/Library/Frameworks/Python.framework/Versions/3.8/bin/python3 %O %S'; but it doesn't work. – jowe_19 Dec 24 '19 at 17:34
  • There should be no $ just before the /Library. When you successfully run 'pythontex' in Terminal what command line do you use? Is that run using python3 or the default python which is 2.x? – Herb Schulz Dec 24 '19 at 18:19
  • Also, which python3 returns /usr/bin/python3 so you probably should refer to it as such rather than through the physical location: the code should be $pythontex = 'pythontex --interpreter python:/usr/bin/python3 %O %S'; – Herb Schulz Dec 24 '19 at 18:45

What happened is that the user didn't put the initialization code in an initialization file that latexmk would read by default. The solution is to put the code in a file that does read. For information on the possible places, see the latexmk documentation in the section 'CONFIGURATION/INITIALIZATION (RC) FILES'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.