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

Text scaling issues #10

Open
mitar opened this issue Jul 1, 2019 · 17 comments
Open

Text scaling issues #10

mitar opened this issue Jul 1, 2019 · 17 comments
Assignees
Milestone

Comments

@mitar
Copy link

mitar commented Jul 1, 2019

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.

@mrpiggi
Copy link
Owner

mrpiggi commented Jul 11, 2019

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 mrpiggi self-assigned this Jul 11, 2019
mrpiggi added a commit that referenced this issue Jul 11, 2019
@mitar
Copy link
Author

mitar commented Jul 11, 2019

Awesome!

@mitar
Copy link
Author

mitar commented Jul 11, 2019

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

@mrpiggi mrpiggi added this to the v2.03 milestone Oct 10, 2019
@pietrocolombo
Copy link

pietrocolombo commented Jan 19, 2020

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}

@mitar
Copy link
Author

mitar commented Jan 19, 2020

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

@pietrocolombo
Copy link

Before:
before
After (inkscapelatex=false):
after

@mitar
Copy link
Author

mitar commented Jan 20, 2020

Try with an example I attached above.

@pietrocolombo
Copy link

pietrocolombo commented Jan 20, 2020

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

@mitar
Copy link
Author

mitar commented Jan 20, 2020

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

@pietrocolombo
Copy link

I have never tried with math formulas

@mitar
Copy link
Author

mitar commented Jan 21, 2020

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?

@mrpiggi
Copy link
Owner

mrpiggi commented Jan 21, 2020

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).

@major-mayer
Copy link

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

@MayeulC
Copy link

MayeulC commented Sep 20, 2022

@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.

@mrpiggi
Copy link
Owner

mrpiggi commented Sep 20, 2022

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.

@schtandard
Copy link

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?

@mrpiggi
Copy link
Owner

mrpiggi commented Nov 16, 2022

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.

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

No branches or pull requests

6 participants