1

I am working on a large document, that contains descriptions of several technical components. I have written several macros that trigger the automatic creation of ".uml" files during a lualatex-compilation of the document. Afterwards, these files may be passed to plantUml, which then creates nice ".png" pictures, that can afterwards be included into the document. All of this works fine.

However, I now wish to automate this process so that creation and inclusion of the diagrams doesn't require two different calls of lualatex and possibly the addition of "\includegraphics{}" in the ".tex"-files.

For this purpose I try to use latexmk with the configuration:

$pdflatex = 'lualatex %O %S ';
$pdf_mode = 1;
$postscript_mode = $dvi_mode = 0;

add_cus_dep('glo', 'gls', 0, 'run_makeglossaries');
add_cus_dep('acn', 'acr', 0, 'run_makeglossaries');
add_cus_dep('uml', 'png', 0, 'uml2png');

sub uml2png {
    system( "java -cp plantuml.jar  net.sourceforge.plantuml.Run -failfast2 -nbtread auto -charset UTF-8 -o . -v -tpng \"$_[0].uml\" \"$_[0].png\"" );
}

sub run_makeglossaries {
    if ( $silent ) {
        system( "makeglossaries -q \"$_[0]\"" );
    }
    else {
        system( "makeglossaries -q \"$_[0]\"" );
    };
}

push @generated_exts, 'uml', 'png';
push @generated_exts, 'glo', 'gls', 'glg';
push @generated_exts, 'acn', 'acr', 'alg';

$clean_ext .= ' %R.ist %R.xdy';

Now, when I try to include "graph.png" that can be computed from "graph.uml" which will be created at the end of the first run of lualatex on the document latexmk aborts telling me that this file is non-existant.

Why is this happening? If I understood the documentation of latexmk correctly, this case should be handled by passing "0" as must-argument to add_cus_dep(from, to, must, conv).

Of course, when I create the required "uml" files in advance they are converted correctly and there are no errors but this lacks automation. Calling lualatex -interaction=nonstopmode also works, but is not an option either.

Can you help me with another solution or explanation of that behaviour?

Thanks in advance.

EDIT: I solved the problem by checking if the uml-files already exist (using IfFileExists), i.e. by postponing the inclusion of the generated graphics:

\newcommand{\generateDiagram}[1]{%
\IfFileExists{%
    #1.uml%
    }{%
    \begin{figure}%
        \includegraphics[width=\textwidth]{#1.png}%
    \end{figure}%
    }{%
    \typeout{Error. No file #1.}%
}%
}%

In the second run the custom dependency is then resolved correctly and the required pictures are created from the .uml-files.

The problem I am now facing is that latexmk seems to be unable to resolve my custom dependency if the files are not stored in the main directory. More precisely I have the following structure:

MAIN
|- FOO (uml goes here)
|- BAR 

I adjusted my add_cus_dep so that the data is read from MAIN/FOO and stored in MAIN/BAR. Now, suppose there is a pic.uml which is generated in the first run and should be included in the second by \generateDiagram{pic}. Latexmk stops and tells me that pic.png doesn't exist (of course it doesn't), without even looking at the dependencies. Can you tell me where I go wrong?

  • You're passing '0' instead of 0 in your add_cus_dep, which probably is evaluated as a truthy value. – ig0774 Sep 23 '16 at 12:31
  • Oh, sorry. That happens to be a result of desperation and is of course incorrect. The problem persists with when using 0 though, so I edited my post. – Mampfred3000 Sep 23 '16 at 13:02

Your Answer

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

Browse other questions tagged or ask your own question.