8

I apologize in advance as I am yet to accept some answers to my previous questions; but I'll dare ask this one, as it is somewhat of a showstopper - consider this example:

\documentclass{article} 

\usepackage[fixpdftex,cmyk,svgnames]{xcolor}
\usepackage[breaklinks]{hyperref}

\newcommand{\myauthors}{Author 1 \\ Author 2 \\ {\color{lightgray}Author 3}}

\hypersetup{pdftitle=My Title, pdfauthor=\myauthors, pdfsubject=My Subject, pdfkeywords=} 

\begin{document}

\noindent\myauthors

\end{document}

Here I get the \myauthors typeset exactly as I want them (the "Author 3" is lightgray) - however, in the PDF properties, the Author metadata shows: "Author 1 Author 2 lightgrayAuthor 3" - that is, the "lightgray" in \color{lightgray} of \myauthors ends up as text for the pdfauthor attribute.

I was wandering - is there some sort of a macro, that would "extract" the typeset "plain text" (that is, only those characters that are typeset) - so I could write, say:

\hypersetup{... pdfauthor=\getPlainText{\myauthors}, pdfsubject=...}

... and get "Author 1 Author 2 Author 3" as PDF author metadata?


Alternatively, I was thinking something along the approach in Macro to convert 'multi-line' text to 'single-line' (remove line breaks?) - that is, use macros like:

\def\pastauth#1{\color{lightgray}#1}
\def\npastauth#1{#1}
\newcommand{\myauthors}{Author 1 \\ Author 2 \\ \pastauth{Author 3}}

... and then somehow define a \getPlainText, where the \pastauth would be temporarily \let to \npastauth (thus avoiding \color{lightgray} altogether) - but I cannot get anything with this... I also tried redefining \color with \@gobbleone, but that doesn't work either

  • 1
    I removed some parts of your code that weren't relevant to the question. Please try to do so yourself before posting a question, keep everything simple (which sometimes isn't so simple itself :)). – doncherry Apr 6 '12 at 9:56
  • Thanks for that, @doncherry - it's just that sometimes I use these snippets to start new examples, and so I like to have some arguments I usually forget standing around :) Cheers! – sdaau Apr 6 '12 at 10:19
10

You need to use the

\texorpdfstring{<TeX string>}{<PDF string>}

macro to define a separate TeX and/or PDF string:

\newcommand{\myauthors}{Author 1 \\ Author 2 \\ \texorpdfstring{\color{lightgray}Author 3}{Author 3}}

The following is a view of the Document Properties using Adobe Acrobat:

PDF meta data

So, your <TeX string> defines the colour, while your <PDF string> uses a "plain text" version (void of \color).

This is supported by hyperref and is also usually associated with math contents in sectional headings, which end up in the PDF bookmarks (which is text-based). For more on this "replacement macro", see the hyperref documentation (HTML version).

  • Fantastic @Werner - many thanks for this answer! Cheers! – sdaau Feb 3 '12 at 7:01

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.