Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log if the generated Python output file is missing #40

Closed
wants to merge 1 commit into from

Conversation

rolk
Copy link

@rolk rolk commented Apr 4, 2014

When the package expects Python output to be present, it attempts to input the .pytxmcr file. If this file is not found, nothing was done, expecting the user to know that pythontex.py should be run.

This patch prints a message to the log which enables scripts such as latexmk to deduce that a file is missing and run pythontex.py automatically to create it (and re-run latex on the original document afterwards).

Such a dependency can be setup if you add the following lines to your latexmkrc:

add_cus_dep('pytxcode','pytxmcr',0,'pythontex');
sub pythontex { return system("pythontex.py \"$_[0]\""); }

When latexmk sees that the .pytxmcr file is missing, it will make it from .pytxcode. When changes are detected for the .pytxcode, it will re-run pythontex.py to update the .pytxmcr file.

Currently, this requires you to specify

\setpythontexoutputdir{.}

so that the .pytxmcr file is expected to be in the same directory as the .pytxcode, as this is the only place latexmk will look for it.

@rolk
Copy link
Author

rolk commented Apr 4, 2014

I am sorry, I just now saw #13 which essentially does the same thing. That issue was closed as "solved in a different manner", but without the log entry, pythontex.py does not get run. (There is no output in the log for \InputIfFileExists)

When the package expects Python output to be present, it attempts to
input the .pytxmcr file. If this file is not found, nothing was done,
expecting the user to know that pythontex.py should be run.

This patch prints a message to the log which enables scripts such as
latexmk to deduce that a file is missing and run pythontex.py
automatically to create it (and re-run latex on the original document
afterwards).

Such a dependency can be setup if you add the following lines to your
latexmkrc:

    add_cus_dep('pytxcode','pytxmcr',0,'pythontex');
    sub pythontex { return system("pythontex.py \"$_[0]\""); }

When latexmk sees that the .pytxmcr file is missing, it will make it
from .pytxcode. When changes are detected for the .pytxcode, it will
re-run pythontex.py to update the .pytxmcr file.

Currently, this requires you to specify

    \setpythontexoutputdir{.}

so that the .pytxmcr file is expected to be in the same directory as
the .pytxcode, as this is the only place latexmk will look for it.
@gpoore
Copy link
Owner

gpoore commented Apr 7, 2014

Which version of PythonTeX and latexmk are you using? Also, are you using latexmk with the -recorder option? At least on my machine, everything works fine when using

add_cus_dep('pytxcode', 'tex', 0, 'pythontex');
sub pythontex {
return system("pythontex \"$_[0]\"") ;
}

from #13 in a .latexmkrc, along with latexmk -pdf <file>.tex.

@rolk
Copy link
Author

rolk commented Apr 8, 2014

Versions used are: latexmk 4.24 (from Ubuntu Precise repositories) and PythonTeX from master branch. Using -recorder has no effect, as the file isn't read.

Adding a dependency from the .tex file only works if you have the .tex file in the same directory as the output.

@gpoore
Copy link
Owner

gpoore commented Apr 8, 2014

I guess I'm not understanding how latexmk isn't working for you. Maybe you can try to describe it a little differently.

If I'm understanding correctly, this is what happens currently: Suppose you have just a .tex document and a .latexmkrc in a directory. latexmk will compile the document. The rule add_cus_dep('pytxcode', 'tex', 0, 'pythontex') will then cause latexmk to run PythonTeX, since a .pytxcode file will now exist. (It's always created in the document directory.) Once PythonTeX is run, latexmk will compile the document again, because the rule says that PythonTeX is used to create the document. During this second compile, the .pytxmcr will exist and will be brought in. When this happens, it will be detected by -recorder. So from that point on, any changes to .pytxcode or .pytxmcr will trigger a recompile.

By the way, regardless of what is necessary to get latexmk working, I will change things so that some comments are written to the log.

@rolk
Copy link
Author

rolk commented Apr 11, 2014

The rule add_cus_dep('pytxcode', 'tex', 0, 'pythontex') will then cause latexmk to run PythonTeX, since a .pytxcode file will now exist. (It's always created in the document directory.

Not necessarily. I have a setup where the .tex source files are stored on a network disk, but the latex program itself is run in a directory on /tmp where all the files are generated.

@gpoore
Copy link
Owner

gpoore commented Apr 13, 2014

That clarifies things a lot. I assume you are using -auxdir, -outdir, or $out_dir, probably with a modified openout_any. Now that I understand your use case better, I should be able get things working.

@rolk
Copy link
Author

rolk commented Apr 22, 2014

I assume you are using -auxdir, -outdir, or $out_dir, probably with a modified openout_any

The approach I am using is actually to add the document directory to TEXINPUTS and BIBINPUTS, and then branch to a temporary directory before calling latexmk (I have everything called by a Makefile, and then do M-x recompile in Emacs), so the current directory is on /tmp.

@gpoore gpoore closed this in 9bc762e Jul 3, 2014
@gpoore
Copy link
Owner

gpoore commented Jul 3, 2014

This should be fixed now. Sorry for the delay. Please open a new issue if you discover any other latexmk-related problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants