TeX - LaTeX Asked by gigabytes on January 12, 2021
I’m trying to write a class where the arguments of the title{}
and author{}
commands, used for the title page, automatically call hypersetup{}
to set the title and the author in the PDF metadata.
So far I use this piece of code (the apptocmd
command is from etoolbox
)
apptocmd{title}{
hypersetup{
pdftitle={#1}
}
}{}{}
It works well, but often it happens that the user wants to insert a newline in the title to tune its appearance:
title{My very long long title}
While everything still works, I get a warning about the newline being an unsupported token for pdf strings. The user is then forced to do:
title{My very long long texorpdfstring{}{} title}
to have the warning silenced.
So the question is: can I automatically remove (or better, replace) tokens that are not allowed in PDF strings according to hyperref
, and to pass the filtered string to hypersetup
to avoid the warning?
If a generic solution is not possible or too difficult, I’d want at the very least to just remove newlines or to replace them with spaces (I’ve tried to simply redefine the command in a group before calling
hypersetup
but I still get the warning).
It can be done with hyperref
's pdfstringdefDisableCommands
:
documentclass{article}
usepackage{etoolbox}
usepackage{hyperref,xpatch}
xapptocmd{title}{%
hypersetup{ pdftitle={#1} }%
}{}{}
pdfstringdefDisableCommands{%
def{}%
}
title{My very long long title}
author{Me}
date{today}
begin{document}
maketitle
end{document}
The example does not remove the extra space in the pdftitle, though…
Correct answer by cgnieder on January 12, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP