Latex export - limitations?

0 votes
asked Jan 31, 2020 in Question / help by CALUM

Not sure what is beyond the capability of latex export and what might be a bug.

1. Font sizes don't seem to be respected.  For example:

@startuml

head: <img:myLogo.png>

skinparam LegendBackgroundColor LightGrey
skinparam LegendFontSize 8

:A;

:B;

legend right
**References:**
# [[http://dx.doi.org/10.1056/NEJMoa1011923 Conroy et al. N Engl J Med 2011; 364:1817-25]] 
# [[http://dx.doi.org/JCO.1997.15.6.2403 Burris et al. J Clin Oncol 1997; 15:2403-13]]
end legend

@enduml

The legend and the A and B are the same size.  Same applies to text elsewhere.  The legend box however is reduced in size, so the text doesn't fit.  It appears the uml gets its font from the latex document (if the document is serif its serif, if its sans its sans)

I'm not good with font sizing in latex!  But if I do: \footnotesize in front of the text in a node it is smaller.  So if plantuml could pass some text sizing info it should be possible.

2. Hyperlinks don't work.  They look like links (blue underline, no link address shown etc, but they aren't clickable

From the example above the latex for the first line of legend is:

\node at (557.6215pt,973.5996pt)[below right,color=black]{1.};

\node at (566.4882pt,973.5996pt)[below right,color=plantucolor0004]{\underline{Conroy et al. N Engl J Med 2011; 364:1817-25}};

Manually 'hacking' that to:

\node at (557.6215pt,973.5996pt)[below right,color=black]{1.};

\node at (566.4882pt,973.5996pt)[below right,color=plantucolor0004]{\href{http://dx.doi.org/10.1056/NEJMoa1011923}{Conroy et al. N Engl J Med 2011; 364:1817-25}};

Gives me a link that opens (should probably actually leave the /underline as this isn't underlined.

(Needs \usepackages{hypperref} in the premble)

3. PNG image in header shows as NULL

The latex code for that is:

\node at (609.1542pt,10pt)[below right]{{null}};

So its plant that is providing the "NULL".  

Replacing that with

\node at (609.1542pt,10pt)[below right]{\includegraphics{myLogo.png}};

Sort of works.  There is a scaling issue because I've scaled the whole think (see below) and this doesn't scale with it but its close to what I'd want.

4. Scaling the image to the page

Outputing a large (wide or tall) uml it runs off the end of the page.  I was able to wrap my code to scale it but it requires a manual edit...

... \begin{tikzpicture}[scale=\tikzscale, yscale=-1,

With this hack in the pre-amble

\usepackage{environ}

\makeatletter
\newsavebox{\measure@tikzpicture}
\NewEnviron{scaletikzpicturetowidth}[1]{%
  \def\tikz@width{#1}%
  \def\tikzscale{1}\begin{lrbox}{\measure@tikzpicture}%
  \BODY
  \end{lrbox}%
  \pgfmathparse{#1/\wd\measure@tikzpicture}%
  \edef\tikzscale{\pgfmathresult}%
  \BODY
}
\makeatother

And then inputing the uml using:

\begin{scaletikzpicturetowidth}{\textwidth}
\input{myFlow.latex}
\end{scaletikzpicturetowidth}

And that is only scaling width not height.

Is there a better way to do this?

What I'm trying to achieve is a PDF document with 5 or 6 full A4 page size UMLs that may need scaled to fit (scale down, but not up).  They need clickable html links.  There will be a parallel set of SVGs which will be embedded in a website.  Those SVGs are clickable (smiley).  The PNG logo is about attributing ownership and copyright info etc and so is needed in the SVGs where they are stand alone files if saved.  The PDF could have them in the other latex bit.

If latex could just import an SVG I'd probably be fine!

commented Feb 1, 2020 by albert (3,520 points)

You wrote: "If latex could just import an SVG I'd probably be fine!"

I think LaTeX can include svg images with \includesvg and \usepackage{svg}

commented Feb 1, 2020 by CALUM Polwart
Ah - yes.  so that /includesvg is actually a rather convoluted process that also doesn't deliver what it needs to!  It uses inkscape on the command line, and uses an inkscape plugin to convert to a tikz which is then inserted into the latex as I understand it!

Inkscape doesn't export the hyperlinks. (I therefore haven't even attempted to progress that any further as that (and ability to search text) are the main reason I wouldn't just export a high reason not to simply export a high res PNG and import that!

3 Answers

0 votes
answered Feb 1, 2020 by CALUM Polwart

2. Hyperlinks don't work.  They look like links (blue underline, no link address shown etc, but they aren't clickable

From the example above the latex for the first line of legend is:

<SNIP>

Gives me a link that opens (should probably actually leave the /underline as this isn't underlined.

(Needs \usepackages{hypperref} in the premble)

Looking at this post:

https://forum.plantuml.net/3558/export-to-tikz-loses-links?show=3558#q3558

It appears this function should already exist but I'm not seeing it.  I haven't tested it in the sequence diagram, I'm using an activity-beta (link in the activity box and link in a legend).  But that sounds like this should work and doesn't.

0 votes
answered Feb 1, 2020 by CALUM Polwart

1. Font sizes don't seem to be respected.  For example:

<SNIP>

The legend and the A and B are the same size.  Same applies to text elsewhere.  The legend box however is reduced in size, so the text doesn't fit.  It appears the uml gets its font from the latex document (if the document is serif its serif, if its sans its sans)

I'm not good with font sizing in latex!  But if I do: \footnotesize in front of the text in a node it is smaller.  So if plantuml could pass some text sizing info it should be possible.

Seems there was some discussion back in 2017 on trying to get boxes to size better (https://forum.plantuml.net/6495/wrong-class-widths-after-latex-export?show=6495#q6495)

Latex (IMHO) is odd in that you neither specify a font or a point size directly!  You specify sans or serif, and you specify size with a set of pre-defined names.  

So you can select a sans font with: \textsf{Sample Text 0123}

So you can select a size with a named size: \small{this is small}

Back then the question of how to add 'Arial' as a font was asked.  You'd need to have this in the preamble:

\usepackage{fontspec}
  \setsansfont{Arial}

And in the node:

{\sffamily This is a sample text in \textbf{Sans Serif Font Typeface}}

You'd need to compile with XeLatex.
https://www.overleaf.com/learn/latex/XeLaTeX
Setting the font size in point size...  (10pt is the font size, 12pt I think is the line spacing, the advice seems to be to make this 1.2x the font size)

    \fontsize{10pt}{12pt}\selectfont{some text}
So building on my earlier example the snip of the legend should be something like:

\documentclass{article}
\usepackage{tikz}
\usepackage{hyperref}
\begin{document}
    \begin{tikzpicture}
        \node at (557.6215pt,973.5996pt)[below right,color=black]
            {\textsf
                {
                \fontsize{8pt}{9.6pt}\selectfont
                    {1. }
                }
            };

        \node at (566.4882pt,973.5996pt)[below right] 
            {\textsf
                {\fontsize{8pt}{9.6pt}\selectfont
                    {\href
                        {http://dx.doi.org/10.1056/NEJMoa1011923}
                        {Conroy et al. N Engl J Med 2011; 364:1817-25}
                    }
                }    
            };
\end{tikzpicture}
\end{document}

0 votes
answered Feb 2, 2020 by plantuml (294,960 points)
Thanks for your detailled report.

The hyperlink issue should be fixed in last beta http://beta.plantuml.net/plantuml.jar

Very few tests have been done, so please tell us if it's working for you.

For other points, it would be nice if you could open a separate question for each of them. Otherwise, it's going to be difficult to follow the discussion in a single answer. Thanks!
commented Feb 3, 2020 by CALUM Polwart
Cheers, initial tests on hyperlink on the latest beta look OK.

Will split the other issues into fresh threads.
...