3

When imported svg into a beamer presentation that uses \pgfsetfillopacity, semi transparency stops working.

For example the code below produces different results with and without loading the package

Without the svg package:

enter image description here

With the svg package:

enter image description here

Is there a way to patch svg or a workaround to use it with beamer semitransparent features? (or maybe the problem is related to pgf?)

    % code from http://tex.stackexchange.com/a/44716/7561
    \documentclass[compress]{beamer}
    \usecolortheme{rose}

    % switch this on or off
    %\usepackage{svg}

    \usebackgroundtemplate{\centering
            \includegraphics[width=\paperwidth,height=\paperheight]{example-image-a}}

    \addtobeamertemplate{block begin}{\pgfsetfillopacity{0.5}}{\pgfsetfillopacity{1}}
    \addtobeamertemplate{block alerted begin}{\pgfsetfillopacity{0.5}}{\pgfsetfillopacity{1}}
    \addtobeamertemplate{block example begin}{\pgfsetfillopacity{0.5}}{\pgfsetfillopacity{1}}

    \begin{document}

      \begin{frame}{}
        \begin{theorem}
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. 
        \end{theorem}

      \begin{alertblock}{Alert!!!}
    Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
      \end{alertblock}

      \begin{exampleblock}{Example}
    Aenean ut gravida lorem. Ut turpis felis, pulvinar a semper sed, adipiscing id dolor. Pellentesque auctor nisi id magna consequat sagittis. Curabitur dapibus enim sit amet elit pharetra tincidunt feugiat nisl imperdiet. Ut convallis libero in urna ultrices accumsan. Donec sed odio eros.
      \end{exampleblock}
      \end{frame}
    \end{document}

Extended example, that includes an .svg file.

% code from http://tex.stackexchange.com/a/44716/7561
\documentclass[compress]{beamer}

\usepackage{filecontents}

\begin{filecontents*}{sample.svg}
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->

<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="19.581747mm"
height="37.898418mm"
viewBox="0 0 69.384143 134.28573"
id="svg2"
version="1.1"
inkscape:version="0.91 r13725"
sodipodi:docname="example.svg">
<defs
id="defs4" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.35"
inkscape:cx="-280.71427"
inkscape:cy="48.571435"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
fit-margin-top="0"
fit-margin-left="0"
fit-margin-right="0"
fit-margin-bottom="0"
inkscape:window-width="1331"
inkscape:window-height="750"
inkscape:window-x="29"
inkscape:window-y="18"
inkscape:window-maximized="1" />
<metadata
id="metadata7">
<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></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-254.2857,-446.64791)">
<path
style="fill:#000000;fill-rule:evenodd;stroke:#000000;stroke-width:0;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 271.42857,580.93363 c 62.85714,-37.14285 51.42857,-85.71428 51.42857,-85.71428 l -68.57143,-48.57143 31.42858,71.42857 z"
id="path4136"
inkscape:connector-curvature="0" />
</g>
</svg>
\end{filecontents*}


\usecolortheme{rose}

% this definition creates an error on the last frame
\makeatletter
  \@namedef{transparent}%
\makeatother

% switch this on or off
\usepackage{svg}

\usebackgroundtemplate{\centering
        \includegraphics[width=\paperwidth,height=\paperheight]{example-image-a}}

\addtobeamertemplate{block begin}{\pgfsetfillopacity{0.5}}{\pgfsetfillopacity{1}}
\addtobeamertemplate{block alerted begin}{\pgfsetfillopacity{0.5}}{\pgfsetfillopacity{1}}
\addtobeamertemplate{block example begin}{\pgfsetfillopacity{0.5}}{\pgfsetfillopacity{1}}

\begin{document}

  \begin{frame}{}
    \begin{theorem}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. 
    \end{theorem}

  \begin{alertblock}{Alert!!!}
Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
  \end{alertblock}

  \begin{exampleblock}{Example}
Aenean ut gravida lorem. Ut turpis felis, pulvinar a semper sed, adipiscing id dolor. Pellentesque auctor nisi id magna consequat sagittis. Curabitur dapibus enim sit amet elit pharetra tincidunt feugiat nisl imperdiet. Ut convallis libero in urna ultrices accumsan. Donec sed odio eros.
  \end{exampleblock}
  \end{frame}

  % this produces an error when \@namedef is used
  \begin{frame}
    \includesvg{sample}
  \end{frame}
\end{document}
9
  • 1
    The source of the problem is, that the svg package load \RequirePackage{transparent}. Sep 2, 2016 at 14:22
  • Possible workaround: make a copy of svg.sty to your working directory, rename it and comment out line 43 \@ifpackageloaded{transparent}{}{\RequirePackage{transparent}}% and use \usepackage{my_svg}. This will probably give issues with transparency in svgs... Sep 2, 2016 at 14:45
  • Or simply convert your svgs before compiling and include the pdf? Sep 2, 2016 at 14:48
  • 1
    Beamer doesn't use real transparency. I am not sure about PGF. transparent is enabling transparency in the PDF colour stack directly. Beamer creates transparency by mixing with the background colour. I don't know what PGF does.
    – cfr
    Sep 5, 2016 at 3:17
  • 1
    PGF is also doing it in the PDF. At a rough guess, it and transparent are competing with each other to inject code into the PDF in ways which conflict e.g. one overwriting the other or something like that. But I'm just guessing.
    – cfr
    Sep 5, 2016 at 3:24

1 Answer 1

2

New solution based on https://tex.stackexchange.com/a/390317/36296

% code from http://tex.stackexchange.com/a/44716/7561
\documentclass[compress]{beamer}

\usecolortheme{rose}

% from https://tex.stackexchange.com/a/390317/36296
\expandafter\def\csname ver@transparent.sty\endcsname{}

% switch this on or off
\usepackage{svg}

\usebackgroundtemplate{\centering
        \includegraphics[width=\paperwidth,height=\paperheight]{example-image-a}}

\addtobeamertemplate{block begin}{\pgfsetfillopacity{0.5}}{\pgfsetfillopacity{1}}
\addtobeamertemplate{block alerted begin}{\pgfsetfillopacity{0.5}}{\pgfsetfillopacity{1}}
\addtobeamertemplate{block example begin}{\pgfsetfillopacity{0.5}}{\pgfsetfillopacity{1}}

\begin{document}

  \begin{frame}{}
    \begin{theorem}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. 
    \end{theorem}

  \begin{alertblock}{Alert!!!}
Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
  \end{alertblock}

  \begin{exampleblock}{Example}
Aenean ut gravida lorem. Ut turpis felis, pulvinar a semper sed, adipiscing id dolor. Pellentesque auctor nisi id magna consequat sagittis. Curabitur dapibus enim sit amet elit pharetra tincidunt feugiat nisl imperdiet. Ut convallis libero in urna ultrices accumsan. Donec sed odio eros.
  \end{exampleblock}
  \end{frame}

\end{document}

Replacing the troublesome svg package with https://www.ctan.org/pkg/svg-inkscape work - this needs inkscape to be installed, but looking at the creator of your sample svg, this should not be a problem.

% !TeX program = txs:///arara
% arara: pdflatex: {shell: true}
\documentclass[compress]{beamer}

\usepackage{filecontents}

\begin{filecontents*}{sample.svg}
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->

<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="19.581747mm"
height="37.898418mm"
viewBox="0 0 69.384143 134.28573"
id="svg2"
version="1.1"
inkscape:version="0.91 r13725"
sodipodi:docname="example.svg">
<defs
id="defs4" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.35"
inkscape:cx="-280.71427"
inkscape:cy="48.571435"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
fit-margin-top="0"
fit-margin-left="0"
fit-margin-right="0"
fit-margin-bottom="0"
inkscape:window-width="1331"
inkscape:window-height="750"
inkscape:window-x="29"
inkscape:window-y="18"
inkscape:window-maximized="1" />
<metadata
id="metadata7">
<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></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-254.2857,-446.64791)">
<path
style="fill:#000000;fill-rule:evenodd;stroke:#000000;stroke-width:0;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 271.42857,580.93363 c 62.85714,-37.14285 51.42857,-85.71428 51.42857,-85.71428 l -68.57143,-48.57143 31.42858,71.42857 z"
id="path4136"
inkscape:connector-curvature="0" />
</g>
</svg>
\end{filecontents*}


\usecolortheme{rose}


\newcommand{\executeiffilenewer}[3]{%
 \ifnum\pdfstrcmp{\pdffilemoddate{#1}}%
 {\pdffilemoddate{#2}}>0%
 {\immediate\write18{#3}}\fi%
}

\newcommand{\includesvg}[1]{%
 \executeiffilenewer{#1.svg}{#1.pdf}%
 {inkscape -z -D --file=#1.svg %
 --export-pdf=#1.pdf --export-latex}%
 \input{#1.pdf_tex}%
}


\usebackgroundtemplate{\centering
        \includegraphics[width=\paperwidth,height=\paperheight]{example-image-a}}

\addtobeamertemplate{block begin}{\pgfsetfillopacity{0.5}}{\pgfsetfillopacity{1}}
\addtobeamertemplate{block alerted begin}{\pgfsetfillopacity{0.5}}{\pgfsetfillopacity{1}}
\addtobeamertemplate{block example begin}{\pgfsetfillopacity{0.5}}{\pgfsetfillopacity{1}}

\begin{document}

  \begin{frame}{}
    \begin{theorem}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. 
    \end{theorem}

  \begin{alertblock}{Alert!!!}
Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
  \end{alertblock}

  \begin{exampleblock}{Example}
Aenean ut gravida lorem. Ut turpis felis, pulvinar a semper sed, adipiscing id dolor. Pellentesque auctor nisi id magna consequat sagittis. Curabitur dapibus enim sit amet elit pharetra tincidunt feugiat nisl imperdiet. Ut convallis libero in urna ultrices accumsan. Donec sed odio eros.
  \end{exampleblock}
  \end{frame}

  % this produces an error when \@namedef is used
  \begin{frame}
    \includesvg{sample}
  \end{frame}
\end{document}

enter image description here

2
  • The workaround works when no \includesvg is used. But when that command exist, it is not found. It seems that the \@namedef messes up the macros from the svg package. See my updated example
    – adn
    Sep 28, 2016 at 17:50
  • @adn See my new workaround Sep 30, 2016 at 10:31

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.