1

I'm using XeLaTeX with Polyglossia.

I have a string like this

Three \emph{blind} Mice, Émile.

saved in a macro, thus:

\gdef\foobar{Three \emph{blind} Mice, Émile.}

and I want to send the text in \foobar into the metadata of a PDF using \pdfinfo{}, thus:

\pdfinfo{/Title (\foobar)}

It doesn't work, because the text in \foobar is sent into the PDF with messy expansion. And the Unicode chars are also messed up.

I've tried some ideas using \noexpand, \expandafter, \toks, but without any success.

Any ideas?

PS don't tell me to use \hyperref's "pdfauthor={}"mechanism, because that clashes with the pdfx package and I can't use it. And I don't want to use pdfx's xmpdata method either. I'm after a solution to the specific issue mentioned, how to change "Three \emph{blind} Mice, Émile."into "Three blind Mice, Emile." Even "Three blind Mice, Émile." would be an improvement.

  • 3
    Please, add a minimal example of code to play with. – egreg Apr 20 '18 at 22:06
  • Since which version is \pdfinfo of pdfTeX supported in XeTeX? – Heiko Oberdiek May 22 '18 at 19:30
  • Using \begingroup \renewcommand{\emph}[1]{#1}% \pdfinfo{/Title (\foobar)} \endgroup should do the trick. If there other formatting commands, they will need to be redefined within the group. – Peter Grill Oct 16 at 16:58
1

Using \pdfinfo is not recommended, if package hyperref is used:

  • \pdfinfo is a low-level driver-specific command, only supported in pdfTeX and LuaTeX.

  • The extracting of markup, the right encoding, the escaping of unmatched parentheses, ... must be done manually.

Package hyperref provides options for setting the metadata. The string is automatically processed by \pdfstringdef.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[pdfencoding=auto]{hyperref}

\hypersetup{
  pdftitle={Three \emph{blind} Mice, Émile.},
}

\begin{document}
  Lorem ipsum.
\end{document}

Option pdfencoding=auto takes care of the encoding of bookmark strings and information meta data. The PDF format supports two encodings:

  • PDFDocEncoding (8-bit)
  • Unicode (UTF-16BE)

with auto the string is encoded in PDFDocEncoding, if it fits there, otherwise Unicode is used.

| improve this answer | |
  • See my PS comment in my original posting above. I can't use \hypersetup because it clashes with another package. – Dominik May 22 '18 at 18:56
  • @Dominik If you are using package pdfx you must stick to its interface (\Author, ...), because the package also has to write the meta data in XML format. Both entries of the author in the PDF meta data and the XML meta data should be the same. If you don't want to use pdfx then do not use it. – Heiko Oberdiek May 22 '18 at 19:25
0

I've just discovered \pdfstringdef, documented in the hyperref manual. It does exactly what I need.

| improve this answer | |
  • 1
    Please add a mininal example of how to use that macro. – lblb Apr 21 '18 at 10:06
  • \pdfstringdef{\TempMice}{Three \emph{blind} Mice, Émile.} /pdfinfo{ (\TempMice) } – Dominik Apr 22 '18 at 0:41
0

\pdfstringdef turns accented characters into octal escape sequence.

Turns : LIPSUM ÉÈÇÀÙÎÏ éèçàùîï 231

Into : LIPSUM \311\310\307\300\331\316\317 \351\350\347\340 231

pdfstringdef octal sequence

From How to make a glowing text?

\documentclass{article}
\usepackage{tikz}
\usepackage[outline]{contour}
\usepackage{hyperref}

\begin{document}

\Huge

Assume pdf\TeX

\def\exText{LIPSUM ÉÈÇÀÙÎÏ éèçàùîï 231}

\makeatletter

    Reverse engineer the contour package.

    Here is an MWE\\
    \leavevmode
    \begingroup
        \color{green}%
        \con@coloroff
        \pdfliteral{%
            q % enter a scope
            1 j % Set line join style
            1 J % Set line cap style
            1 Tr % Set text rendering mode
            2.5 w % Set line width (in PostScript Point)
        }%
        \rlap{\exText}%
        \pdfliteral{%
            Q % leave the scope
        }%
    \endgroup
    \mbox{\exText}


    Now use TikZ.\\
    \pdfstringdef\plainstr{\exText} % Extraction chaine 'nettoyée'
    \leavevmode
    \pgfsys@beginscope% = pdf literal q
    \pgfsetroundjoin% = 1 J
    \pgfsetroundcap% = 1 j
    \pdfliteral{1 Tr}% no pgf alternative
    \foreach\ind in{10,...,1}{%
        \pgfmathsetmacro\per{(11-\ind)*5}%
        \color{green!\per}%
        \pgfsetlinewidth{\ind/2}%
        \rlap{\plainstr}%
    }%
    \pgfsys@endscope % = pdf literal Q
    \plainstr

\makeatother

\end{document}
| improve this answer | |
  • 1
    Welcome, although I don't understand how this is supposed to be an answer to the present question. – egreg Oct 16 at 16:49
  • This is not an answer, this is comment, but as a "freshman", I have to accumulate 50 "likes" before I can comment, but not post an answer. Yet I can comment my own "answer". Go figure... This online gaming/ranting platform have strange rules :/ – Kochise Oct 17 at 7:59

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.