svg icon indicating copy to clipboard operation
svg copied to clipboard

Text scaling issues

Open mitar opened this issue 5 years ago • 17 comments

I cannot really get text to correctly align with the image. I am guessing because the image is heavily scaled down. I tried using pretex=\tiny and pretex=\relscale{0.1} but it is still off (text too large).

I am thinking that maybe a solution would be if:

  • Inkscape is used to convert to PDF + LaTeX.
  • pdflatex is used on empty LaTeX document with just including that PDF + LaTeX to generate a new PDF file, but with LaTeX fonts.
  • I then include that PDF file into my main document, scaling it as necessary.

That would make it use the LaTeX fonts but allow precise scaling as needed.

It looks like this package could support that but it is not yet fully possible? So svg-extract could extract to a separate PDF with custom preamble in extractpreamble, but then I think that instead of the original image the extracted PDF should be included in the main document.

mitar avatar Jul 01 '19 06:07 mitar

If I get you right you are trying to extract a large picture, where the text actually is in the right size but the resulting image has to be scaled down for inclusion in the document, right? Well, currently not an easy task but could be done with something like

\documentclass{scrartcl}
\ifpdftex{
  \usepackage[T1]{fontenc}
}{
  \usepackage{fontspec}
}
\usepackage{svg}
\usepackage{svg-extract}

\begin{document}
\section*{This is a test}
\begin{figure}
\centering
\includesvg[%
  exclude,
  extractpath=basedir,extractname=filename,%
  pretex=\Huge,
  extractwidth=50cm
]{svg-example}
\IfFileExists{svg-example_svg-tex-extract.pdf}{%
  \includegraphics[width=\textwidth]{svg-example_svg-tex-extract.pdf}%
}{}
\end{figure}
\end{document}

As you can see, this is a combination of using \includesvg for extraction and \includegraphics afterwards.

I will try to create a new command \includesvgextracted but this will probably will last some time as I have to think about how this could be implemented regarding for example the handling of passed parameters, extracted file type and more.

Included SVG file Result

mrpiggi avatar Jul 11 '19 13:07 mrpiggi

Awesome!

mitar avatar Jul 11 '19 19:07 mitar

Just to give you an example which was tricky: pipeline-test.zip

mitar avatar Jul 11 '19 19:07 mitar

I solved it like this:

\begin{figure}[ht]
    \centering
    \includesvg[inkscapelatex=false, scale=0.6, keepaspectratio]{plot/number_trip_week_day.svg}
    \caption{caption}
\end{figure}

pietrocolombo avatar Jan 19 '20 09:01 pietrocolombo

I think this works when image is not really really huge.

mitar avatar Jan 19 '20 16:01 mitar

Before: before After (inkscapelatex=false): after

pietrocolombo avatar Jan 20 '20 08:01 pietrocolombo

Try with an example I attached above.

mitar avatar Jan 20 '20 16:01 mitar

With the example I obtain this:

\documentclass{scrartcl}
\ifpdftex{
  \usepackage[T1]{fontenc}
}{
  \usepackage{fontspec}
}
\usepackage{svg}
\usepackage{svg-extract}

\begin{document}
\section*{This is a test}
\begin{figure}
  \centering
  \includesvg[inkscapelatex=false, scale=0.13]{pipeline-test.svg}
  \caption{}
\end{figure}
\end{document}
Screenshot 2020-01-20 at 21 04 10 This is without inkscapelatex=false Screenshot 2020-01-20 at 21 04 42

pietrocolombo avatar Jan 20 '20 20:01 pietrocolombo

Oh, yes, but with inkscapelatex=false then one cannot enter math formulas and stuff for text, no?

mitar avatar Jan 20 '20 20:01 mitar

I have never tried with math formulas

pietrocolombo avatar Jan 21 '20 16:01 pietrocolombo

I mean, this is the mean reason why to use this package, no? Otherwise I can just export SVG to PDF myself and embed it as PDF into my LaTeX document? If I understand correctly, setting inkscapelatex=false does that?

mitar avatar Jan 21 '20 18:01 mitar

I mean, this is the mean reason why to use this package, no? Otherwise I can just export SVG to PDF myself and embed it as PDF into my LaTeX document? If I understand correctly, setting inkscapelatex=false does that?

On the whole, yes, but with a few little things added (like the path search or the automatic invocation of the Inkscape export after an update of the SVG file).

mrpiggi avatar Jan 21 '20 21:01 mrpiggi

I have a problem that seems related to this issue. If i include a SVG using the option inkscapelatex=false the chart looks like this: grafik

If i use pretex=\relscale{0.55} instead, the result looks more or less okay, but the title of the chart is far too small and moved to the left ...? grafik

If i completely remove the pretex option the font is way too large: grafik

I guess for now i just use the inkscapelatex=false, but it's not perfect, because the font type doesn't match with the rest of the document. If you got other ideas please tell me

major-mayer avatar Nov 11 '21 12:11 major-mayer

@major-mayer Your title is probably not centered. It's actually the text-anchor css property that has to be set to middle on the parent xml element. There is actually an inkscape export bug related to this: https://gitlab.com/inkscape/inkscape/-/issues/1170

Long story short: open the svg in inkscape, press "T" to enter text edit mode, click on your title, then in the toolbar, select the "center" option. Do not select text while doing so, or it will set the alignment to the wrong xml element, and it will get ignored during export.

You'll see a small square box in inkscape, positioned at the middle of your text box. That is the anchor, text will be centered around it. Move the title around to the desired position.

Regarding the font size, you can probably prefix it with \large in the svg, though I haven't tried it.

MayeulC avatar Sep 20 '22 12:09 MayeulC

Thanks @MayeulC for the info. There was a similar bug report on tex.se some weeks ago. I will place the appropriate notices in both places.

mrpiggi avatar Sep 20 '22 19:09 mrpiggi

Let me give my two cents regarding this: The main advantage of using inkscapelatex (besides being able to use macros and format math) is that the text font and size in the image will match the rest of the document. If \tiny text is still too large for the image, this is a sign that the image needs to be reworked, as \tiny is already too small to be easily readable. I regard the fact that it is non-trivial to realize microscopic text to be a feature, not a bug. (This, by the way, is not really a feature of the svg package but of LaTeX itself. All the methods to realize those font sizes that work in the rest of the document still work with svg.)

Thus, I would vote against including somethign like \includesvgextracted in this package. Hacks like this are not good practice and should thus not be encouraged. If someone really wants to use it, they can explicitely introduce the hack in their document.

Now, the fact that many people are confused about how text in the svg file translates to the typeset text in their document may suggest that this should be documented in a more visible manner by incorporating the relevant information from svg-inkscape (which is already linked to from the documentation). Or maybe just referencing it more explicitly ("for a detailed description of how text in the svg file translates to text in the typeset document see there") would be enough?

schtandard avatar Nov 16 '22 13:11 schtandard

I totally agree with you there. I will place a clear notice at the beginning of the documentation for the next release. I had already started working on v2.03 a long time ago. Due to lack of time, however, the work has come to a complete standstill and at the moment I cannot make any reliable statement as to when I will be able to continue working on it.

mrpiggi avatar Nov 16 '22 14:11 mrpiggi