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

svg-extract incompatibility with filecontents #59

Open
schtandard opened this issue Mar 19, 2024 · 2 comments
Open

svg-extract incompatibility with filecontents #59

schtandard opened this issue Mar 19, 2024 · 2 comments

Comments

@schtandard
Copy link

Compiling the MWE

% !TeX TXS-program:compile = txs:///pdflatex/[--shell-escape]
\begin{filecontents}[noheader]{drawing.svg}
<?xml version="1.0" encoding="UTF-8"?>
<svg width="96.725mm" height="50.327mm" version="1.1" viewBox="0 0 96.725 50.327" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
 <metadata>
  <rdf:RDF>
   <cc:Work rdf:about="">
    <dc:format>image/svg+xml</dc:format>
    <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
    <dc:title/>
   </cc:Work>
  </rdf:RDF>
 </metadata>
 <g transform="translate(-27.689 -45.179)">
  <path d="m100.09 88.093-6.259-9.7729-10.235 5.4701 3.7384-10.987-10.658-4.5917 10.921-3.9274-3.0554-11.196 9.8795 6.0894 6.8483-9.3694 1.3988 11.521 11.595-0.48748-8.1351 8.2767 7.6106 8.7615-11.543-1.1998z" fill="#ff0808"/>
  <text x="83.593781" y="83.789787" fill="#000000" font-family="'CMU Serif'" font-size="12.7px" letter-spacing="0px" stroke-width=".26458" text-align="end" text-anchor="end" word-spacing="0px" style="line-height:1.25" xml:space="preserve"><tspan x="83.593781" y="83.789787" font-size="3.8806px" stroke-width=".26458" text-align="end" text-anchor="end">This is a test: $\sum_{k = 0}^\infty 2^{-k} = 2$</tspan></text>
 </g>
</svg>
\end{filecontents}

\documentclass{article}

\usepackage[inkscapearea=page]{svg}
\usepackage{svg-extract}

\begin{document}

\includesvg{drawing}

\end{document}

results in the somewhat obscure error message

Runaway argument?
! File ended while scanning use of ^^M.
<inserted text> 
                \par 
<*> 1-drawing_svg-tex.tex

Looking at 1-drawing_svg-tex.tex we can discover the problem.

%% This file was generated by package `svg-extract'
%% from source `test'
%% It's intended to be compiled with `pdflatex' 
\AtBeginDocument{%
  \svgxsetpapersize%
}
\PassOptionsToPackage{hidelinks}{hyperref}
\begin {filecontents}[noheader]{drawing.svg}
<?xml version="1.0" encoding="UTF-8"?>
<svg width="96.725mm" height="50.327mm" version="1.1" viewBox="0 0 96.725 50.327" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<metadata>
<rdf:RDF>
<cc:Work rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
<dc:title/>
</cc:Work>
</rdf:RDF>
</metadata>
<g transform="translate(-27.689 -45.179)">
<path d="m100.09 88.093-6.259-9.7729-10.235 5.4701 3.7384-10.987-10.658-4.5917 10.921-3.9274-3.0554-11.196 9.8795 6.0894 6.8483-9.3694 1.3988 11.521 11.595-0.48748-8.1351 8.2767 7.6106 8.7615-11.543-1.1998z" fill="#ff0808"/>
<text x="83.593781" y="83.789787" fill="#000000" font-family="'CMU Serif'" font-size="12.7px" letter-spacing="0px" stroke-width=".26458" text-align="end" text-anchor="end" word-spacing="0px" style="line-height:1.25" xml:space="preserve"><tspan x="83.593781" y="83.789787" font-size="3.8806px" stroke-width=".26458" text-align="end" text-anchor="end">This is a test: $\sum _{k = 0}^\infty 2^{-k} = 2$</tspan></text>
</g>
</svg>
\end {filecontents}
\documentclass {article}
\usepackage [inkscapearea=page]{svg}
\usepackage {svg-extract}

\usepackage{svg-extract}
\svgxsetbox[lastpage=1]{./svg-inkscape/drawing_svg-tex.pdf}
\usepackage{xr}
\externaldocument{test}

\begin{document}
\pagestyle{empty}
\svgxoutputbox%
\end{document}

All the macros from the original file's preamble are followed by a space. This is not a problem for most macros, but it is in the case of \end {filecontents}.

As a workaround, the filecontents environment can be moved inside the document environment to avoid it being copied to the extraction file (or a different extractpreamble can be used).

@mrpiggi
Copy link
Owner

mrpiggi commented Mar 20, 2024

Thanks for the report and the provided workaround. I probably have to adapt the catcodes when grabbing the preamble of the main document. I will have some time in June, so that I can work on a new version addressing all the open issues.

@AJJLagerweij
Copy link

I want to add another example where the added whitespace causes problems. My preamble contains

\makeatletter
	\newcommand*{\saved@uline}{}
	\let\saved@uline\uline
	\newcommand*{\mathuline}{\mathpalette{\math@uline\saved@uline}}
	\newcommand*{\math@uline}[3]{\mbox{#1{$#2#3\m@th$}}}
	\renewcommand*{\uline}{\relax \ifmmode \expandafter\mathuline \else \expandafter\saved@uline\fi}
\makeatother

for defining 1st, 2nd, till 4th order tensors with underline notation in math mode (this notation is also used in some of the svg images). The problem is that this notation gets converted into:

\makeatletter
\newcommand *{\saved @uline}{}
\let \saved @uline\uline
\newcommand *{\mathuline }{\mathpalette {\math @uline\saved @uline}}
\newcommand *{\math @uline}[3]{\mbox {#1{$#2#3\m @th$}}}
\renewcommand *{\uline }{\relax \ifmmode \expandafter \mathuline \else \expandafter \saved @uline\fi }
\makeatother

the added whitespace before the @ symbol causes this to error out. If I remove these, it runs fine.

I'm not to great with latex, so currently I just manualy remove the whitespace, and then run the image.tex file. But a fix that prevents this from happening would be nice.

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

No branches or pull requests

3 participants