[Tex/LaTex] Change text color when inserting a pdf_tex image

colorinkscape

I am inserting an image from Inkscape using the pdf + LaTeX option since I want the text to appear in the same font and size as in the rest of my document.

Can I change the color of the text?

\documentclass{article}
\usepackage{graphicx}
\usepackage{color}

\begin{document} 
Some text before the figure.

\color{red}

\begin{figure}
 \centering
 \def\svgwidth{\textwidth}
 \input{figure.pdf_tex}
 \caption{Example Figure}
\end{figure}

Some text after the figure.
\end{document}

The following is the content of the figure.pdf_tex file:

\begingroup%
  \makeatletter%
  \providecommand\color[2][]{%
    \errmessage{(Inkscape) Color is used for the text in Inkscape, but the package 'color.sty' is not loaded}%
    \renewcommand\color[2][]{}%
  }%
  \providecommand\transparent[1]{%
    \errmessage{(Inkscape) Transparency is used (non-zero) for the text in Inkscape, but the package 'transparent.sty' is not loaded}%
    \renewcommand\transparent[1]{}%
  }%
  \providecommand\rotatebox[2]{#2}%
  \ifx\svgwidth\undefined%
    \setlength{\unitlength}{782.075bp}%
    \ifx\svgscale\undefined%
      \relax%
    \else%
      \setlength{\unitlength}{\unitlength * \real{\svgscale}}%
    \fi%
  \else%
    \setlength{\unitlength}{\svgwidth}%
  \fi%
  \global\let\svgwidth\undefined%
  \global\let\svgscale\undefined%
  \makeatother%
  \begin{picture}(1,0.48489595)%
    \put(0,0){\includegraphics[width=\unitlength]{figure.pdf}}%
    \put(0.21413974,0.24055332){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{Text}}}%
  \end{picture}%
\endgroup%

The example figure as jpg

Best Answer

The figure envirnoment always resets the color to the document default, normally black so you need the \color command inside the environment.

\begin{figure}\color{red}

That will make any text in the environment including the caption go red.

Then inkscape has hardwired the colors of the text

 \put(0.21413974,0.24055332){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{Text}}}%

so if you want it to pick up the current color you need to remove the

\color[rgb]{0,0,0}

or alternatively redefine the command to do nothing after you have set your color so

 \begin{figure}\color{red}\renewcommand\color[2][]{}

will set red then disable any other \color commands in the figure so you don't need to edit the generated file.