3

This post mentioned that when using PdfLaTeX, One can recolor the blacks of an image to any color using \color.

The Goal: Create an image (preferably scalable(svg)) that can be color adjusted inside LaTeX.

So I created a small black svg vector image in inkscape and saved it as a PDF (with the "PDF+LaTeX", "PDF 1.5" and "use exported object's size" settings), but when I include it with color it stays black...

\definecolor{accent}{RGB}{0, 130, 240} %blue
\color{accent} \includegraphics[height=9pt,clip]{location}

So how do I make a svg image color adjustable in LaTeX?

LinG
  • 355
  • Welcome to [tex.se]! Are there colour settings in your image? – Andrew Swann Feb 17 '17 at 10:39
  • How do I check that? – LinG Feb 17 '17 at 10:42
  • You should be able to read this in the svg file - it is just an xml format. – Andrew Swann Feb 17 '17 at 11:13
  • the only two properties that contain the word "color" in their name are pagecolor="#ffffff" and bordercolor="#666666". Besides, why does it matter if my svg file contains color settings? I'm exporting it as a PDF, so shouldn't the pdf not contain any color settings? Also I tried to export it as PNG as well but that didn't work either... – LinG Feb 17 '17 at 11:45
  • The technique you are trying to use only works on figures without explicit colour settings. It is overriding a default colour. Colours are also specified in svg files by fill and stroke commands amongst other things. You should adjust the colours outside of latex. – Andrew Swann Feb 17 '17 at 12:29
  • Another way to think about this: In general, the \color command only works at the time the object is created. It does not act on an object that was already created. –  Feb 17 '17 at 15:17
  • @AndrewSwann alright, so I set the fill and stroke to none, my svg now reads: style="opacity:1;fill:none;stroke:none;stroke-width:2.5;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"

    But when I convert it to pdf and try to includegraphics it now shows nothing when I include it (makes sense since the color of the object is nothing) but what settings do I need then so I can adjust it in LaTeX?

    – LinG Feb 20 '17 at 09:34
  • @RobtA That makes sense, so how does one create an image without color settings? That can be included in LaTeX and color adjusted? – LinG Feb 20 '17 at 09:40
  • I don't know how to do that. I work with print (paper) books, where there is no need for vector artwork, since scalability is not useful. Instead, I create a raster image at exact size and resolution in a graphics editor (such as GIMP). The LaTeX color commands do not act on a raster image, only on text or text-like objects. –  Feb 21 '17 at 19:50

1 Answers1

3

I suggest an alternative approach to some of the comments:

Use commandline tools to edit the svg file, then import that using the svg package (which in turn converts to pdf using imagemagick).

You might for example (on linux or with cygwin on windows) use something like sed -i 's/fill:#000000/fill:#ff00000' test.svg to switch black to red. From within pdflatex you can use \immediate\write18

In full:

\documentclass{article}
\usepackage{graphicx}
\usepackage{svg}

\begin{document}
\includesvg{test}
\immediate\write18{sed 's/fill:#000000/fill:#ff0000/' test.svg >test1.svg}
\includesvg{test1}
\end{document}
Chris H
  • 8,705