1

I started to use latexmk to compile to pdf. The command I use is

 latexmk -lualatex -jobname="LUA" -silent  index.tex

Since my latex files are very large, it takes about 4-6 hrs to compile to pdf (some are over 60,000 pages) and requires 2-3 runs each time. Here is one example run which is still running for hrs now

latexmk -lualatex -jobname="LUA" -silent  index.tex
Rc files read:
  NONE
Latexmk: File-database 'LUA.fdb_latexmk' is of incompatible version, 3 v. current version 4
Latexmk: Run number 1 of rule 'lualatex'
This is LuaHBTeX, Version 1.15.1 (TeX Live 2023/dev) 
 restricted system commands enabled.
Latexmk: fls file doesn't appear to have been made.
Latexmk: Getting log file 'LUA.log'
Latexmk: Run number 2 of rule 'lualatex'
This is LuaHBTeX, Version 1.15.1 (TeX Live 2023/dev) 
 restricted system commands enabled.
Latexmk: fls file doesn't appear to have been made.
Latexmk: Getting log file 'LUA.log'
Latexmk: Run number 3 of rule 'lualatex'
This is LuaHBTeX, Version 1.15.1 (TeX Live 2023/dev) 
 restricted system commands enabled.

My question is this: Is it possible to make a backup file of the pdf file generated after each run before starting the next run, naming it say LUA_backup.pdf? (Because once a new run starts, the PDF file from the last run is erased automatically).

enter image description here

This way I can view the backup file (even if it not the final version) while waiting for the final version to be completed which will take many hrs more?

I used to do that before, when I was using my own script, but now since I switched to using latexmk I do not know how to do that. I looked at Latexmk options, but do not see one, so thought to ask maybe there is and I overlooked it.

TL 2022

>latexmk --version
Latexmk, John Collins, 18 Nov. 2022. Version 4.78
>which latexmk
/usr/local/texlive/2022/bin/x86_64-linux/latexmk
>
Nasser
  • 20,220
  • 1
    Why not simply use a script which just backs up the pdf file and then invokes latexmk? For a solution purely within latexmk, have a look at the documentation for latexmk's $compiling_cmd variable; it can be used to do whatever you want before latexmk starts to process your document. – John Collins Jan 06 '23 at 16:31
  • @JohnCollins I think I did not make my question clear enough? But I did say Is it possible to make a backup file of the pdf file generated after each run before starting the next run, what I mean by run in the above is the two or 3 runs that latexmk does each time. I did not mean to make backup before the latexmk command starts. ofcourse I can always do that myself. But I meant during latexmk running, i.e. between run 1 and 2, and between run 2 and 3. I have no control over that, only latexmk itself can do that. May be new option latexmk --backup_during_run – Nasser Jan 06 '23 at 18:40
  • Will using $compiling_cmd variable; make latexmk make a backup of the PDF file between each run? Or only before the initial latexmk command starts? I need the backup between each run not just before the initial command is issued. But I will try and find out also. I am new using latexmk – Nasser Jan 06 '23 at 18:50
  • Sorry, I misunderstood. Your question was clear, but I'd confused your problem with another that I've encountered. The simplest thing I can think of is to modify the $lualatex variable, which is what determines what is actually done when latexmk wants to run lualatex. You could arrange it to run lualatex and then copy the pdf file to where you want it for viewing. You can see some examples in the latexmk documentation, which you could modify. Another source of ideas is in the example latexmkrc files in the example_rcfiles of the latexmk distribution. – John Collins Jan 06 '23 at 20:12
  • I should add that one simple possibility is for $lualatex to cause latexmk to invoke a script of yours, say by replacing lualatex in the default value of $lualatex by the name of your script. The script would run lualatex and then copy the pdf file. That would be the simplest solution if you already has a script that does what you want or can be easily modified for the current situation. I've done this sort of thing on occasion. – John Collins Jan 06 '23 at 20:18

1 Answers1

1

Solution 1. (Ab)use add_cus_dep

Inspired from PythonTeX's method of using add_cus_dep. Add the following to .latexmkrc:

sub backup_pdf{
    print("Backup the PDF $_[0].pdf -> $_[0]-backup.pdf\n");
    system("cp \"$_[0].pdf\" \"$_[0]-backup.pdf\"");
    #system("cp \"$_[0].synctex.gz\" \"$_[0]-backup.synctex.gz\"");  # optional
}
add_cus_dep('pdf', 'tex', 0, 'backup_pdf');

Explanation from PythonTeX documentation:

This is a slightly atypical use, if not a “misuse,” of add_cus_dep(). In the standard usage, the first argument is the extension of a file that is used to create another file with the extension given in the second argument, via the rule named in the fourth argument. In this case, we just want to run the rule whenever files with the first extension are modified. The extension given in the second argument is irrelevant, so long as a file with the document name and that extension exists. Since the tex file itself will exist, its extension is a logical choice for the second argument.


I tried a few other solutions which all doesn't work.

  • (Ab)use $pdf_update_command

    The actual purpose of this variable is:

    $pdf_update_command [""]

    When the pdf previewer is set to be updated by running a command, this is the command that is run. See the information for the variable $pdf_update_method.

    Inspired from https://gist.github.com/yig/dc648aef95e7a44217be.

    Nevertheless, it only runs at the very end of a compilation.

  • Use $compiling_cmd, $failure_cmd, etc.

    Also doesn't work.

  • Use extra_rules_spec

    Following https://tex.stackexchange.com/a/685550/250119, I thought something like this would work, but it doesn't.

    sub backup_pdf{
        print("Backup the PDF ($_[0].pdf)");
        system("cp \"$_[0].pdf\" \"$_[0]-backup.pdf\"");
    }
    

    $extra_rule_spec{'backup_pdf_rule'} = [ 'internal', # cmd_type '', # ext_cmd 'backup_pdf', # int_cmd "%Z%R.pdf", # '%Z for $out_dir1' "%Z%R-backup.pdf", # dest "%R", # base ('%R = root = base for latex') 1 # needs_making ];

user202729
  • 7,143