4

I would like to set up a package with some logos for titles and fancy headers and the like. The key problem that I have at this point is that it should be possible to get the logo in different colors. The logo is available as PNG, JPG, EMF or SVG.

I am aware of some (partial) solutions, but they either seem to be not quite the "right" solution or I lack some details as to how to actually make the solution work:

  1. Convert SVG to PDF and include a logo for every color that is needed in the package. Easy, but does not really scale.
  2. Use the PNG (which has a white background) and the TikZ blender trick found here or the TikZ fading trick from this answer. The resolution of the PNG might be good enough for documents, but I would prefer vector graphics in order to get good looking beamer presentations.
  3. Use the JPG and apply the solution suggested in this answer. The main problem with this approach is that it is not entirely clear to me whether/how this could allow setting the logo to a specific color.
  4. Convert SVG to "colorless" PDF and use something like {\color{mycolor} \includegraphics{logo.pdf}} (as suggested in this answer or this other answer). However, I have tried different ways to convert the SVG to PDF and all tools seem to set the color in the PDF, since the include did not work. Also manually fiddling with the PDF does not seem to be a reasonable solution.
  5. Use the svg package to load the SVG directly (as suggested in the answer to this question). However, this does not seem to work on Windows, which would be very inconvenient.
  6. Convert SVG to TikZ code and include the TikZ pictures (as discussed here). This allows to change colors on the fly, but I am a little concerned about performance. E.g. if the package would be used for a beamer presentation where the logo appears on every slide, the TikZ image would be rendered separately for every slide (if I understood that correctly). I am aware of the standalone package, but since it seems to build the TikZ images in the user directory (when using mode=build or the like) I am also a little hesitant of this approach.
  7. (in some sense similar to 4) Convert SVG to TikZ code (as in the previous point) to render a "colorless" PDF. This question shows how the picture environment can be used to create a "colorless" PDF and seems to hint that it should also be possible with TikZ, but as soon as I add \usepackage{tikz} to the provided MWE, the PDF is no longer colorless. I also failed to find out whether/how to render a "colorless" PDF with TikZ.

Maybe it is worth mentioning that the logo that should be included has been changed quite a bit recently. Therefore, it would be great if the required file could be created with little to no manual intervention. Also, the package should be easy to install/use.

Currently, options 6 and 4/7 look most promising, but it would be great if the images could be built "out-of-sight" for 6 or when someone could point me to how a "colorless" pdf could be generated.

Feel free to add options, if I forgot something!

5
  • I think you forgot a link to [this question] in option 5? – Abby Jul 8 '20 at 16:08
  • @Abby I rather messed something up while copy-pasting everything to the right spot. Thanks for the heads up, I cleaned it up! – Mr Tsjolder Jul 9 '20 at 6:50
  • If that logos are set by using LaTeX codes, can able to change the color as you expected, but if those are in image format, nothing to fix...(as of my knowledge) – MadyYuvi Jul 9 '20 at 9:22
  • @MadyYuvi The logo would be black on white. The links in my question point to different solutions to set the color of that black area within LaTeX. – Mr Tsjolder Jul 9 '20 at 9:32
  • 1
    I am sure I got not all, but there are 'logo'-packages at LaTeX, and I think that are more fonts than graphics. So if your startpoint is SVG (Inkscape?) why not using a font-software like FontForge? I make some things with Japanese symbols; and after some tries with TikZ, I work more with Inkscape and FontForge. – cis Sep 6 '20 at 9:54
2

7. Colorless PDF

Each user/package can implement colors for the PDF file using low level commands directly (\pdfliteral, \pdfcolorstack, '\special{...}, ...). In case of LaTeX, the color packages colororxcolor are used that add color support to LaTeX. The driver files (pdftex.def, dvips.def`, ...) define the macros for LaTeX's color interface:

  • \set@color
  • \reset@color
  • \set@page@color

Thus, these commands can be redefined again to suppress the color settings:

\usepackage{color}
\makeatletter
\let\set@color\relax
\let\reset@color\relax
\let\set@page@color\relax
\makeatother

Package xcolor

The package file xcolor.sty executes \color{black} at the end of the package. Thus a redefinition of \set@color after the package is loaded comes too late. The workaround is a tricky load and redefinition order:

% 1. Load package color that loads the driver file that defines
%    \set@color, \reset@color, and \set@page@color.
\usepackage{color}

% 2. Redefine the low level color commands.
\makeatletter
\let\set@color\relax
\let\reset@color\relax
\let\set@page@color\relax
\makeatother

% 3. Load package xcolor that detects that the driver file is already loaded.
%    Therefore, the low level color commands are not redefined and
%    \color{black} at the end is not setting the color.
\usepackage{xcolor}

If the xcolor package is already loaded in the class, then package color can be loaded before:

\RequirePackage{color}
\makeatletter
\let\set@color\relax
\let\reset@color\relax
\makeatother

\documentclass[tikz]{standalone}% Example, this loads package xcolor

At the time of loading, package color does not see global options. If needed, the options have to be given at \RequirePackage again. (E.g. driver options for pdfTeX, LuaTeX, and XeTeX are not needed, because these TeX engines can be automatically detected at the TeX language level. The configuration file color.cfg does this for TeX Live, MikTeX, ...)

Package tikz

TikZ graphic can contain both color setting by the (x)color packages or its own color settings, as defined in pgfsys-common-pdf.def. Also these color definitions can be redefined after TikZ/pgf is loaded:

\makeatletter
\def\pgfsys@color@rgb@stroke#1#2#3{}
\def\pgfsys@color@rgb@fill#1#2#3{}
\def\pgfsys@color@cmyk@stroke#1#2#3#4{}
\def\pgfsys@color@cmyk@fill#1#2#3#4{}
\def\pgfsys@color@cmy@stroke#1#2#3{}
\def\pgfsys@color@cmy@fill#1#2#3{}
\def\pgfsys@color@gray@stroke#1{}
\def\pgfsys@color@gray@fill#1{}
\makeatother

Debugging

The following settings for pdfTeX allow uncompressed PDF files for reviewing the PDF files in a text viewer to detect color commands in page streams:

\pdfobjcompresslevel=0
\pdfcompresslevel=0

XeTeX uses the program xdvipdfmx for the output driver, the option for uncompressed output file must be passed to the latter, the command call to XeLaTeX becomes to

 xelatex -output-driver="xdvipdfmx -z 0"

The typical color commands in the PDF file (there are others, for a full list see the PDF specification):

<gray> G
<gray> g
<red> <green> <blue> RG
<red> <green> <blue> rg
<cyan> <magenta> <yellow> <black> K
<cyan> <magenta> <yellow> <black> k

Uppercase operators are for stroking operations, lowercase operators for filling. The arguments in angle brackets are decimal numbers between 0 and 1. Example: 0 g 0 G is the default color setting to black.

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.