Sorry to come back again with a similar post title (I had a post with this same title, then renamed it to PDF Metadata - Macro to extract (typeset) 'plain text' from a command?) - but I hope now the question can be narrowed down a bit...
Let's say you have something like
\def\mystring{Test of math $a^{b}$, \textbf{bold} and some {\color{lightgray}coloring}}
I would like to use/know of a macro, which could accept \mystring
, and return a "plain" text version of it. I would be quite satisfied with the math being dropped - however, I'd like the letters pulled out, where I'd otherwise have text typeset. Let's say we call such a macro \getPlainText
- then I'd be very satisfied with something that would behave like this:
* \typeout{ \getPlainText{\mystring} }
Test of math , bold and some coloring
Basically, I think I could use this in a couple of ways (but mostly in response to hyperref
stuff):
Within PDF metadata
In hyperref - PDF Metadata - Macro to extract (typeset) 'plain text' from a command?, the answer to correct display of "latexed" PDF metadata is to use \texorpdfstring
as such:
\newcommand{\myauthors}{Author 1 \\ Author 2 \\ \texorpdfstring{\color{lightgray}Author 3}{Author 3}}
...
\hypersetup{..., pdfauthor=\myauthors, ...}
Here, I'd much rather prefer a syntax with "getPlainText" as so:
\newcommand{\myauthors}{Author 1 \\ Author 2 \\ {\color{lightgray}Author 3}}
...
\hypersetup{..., pdfauthor=\texorpdfstring{\myauthors}{\getPlainText{\myauthors}}, ...}
Within PDF TOC bookmarks related to sections titles with math
In mathmode - Equations in section heading/title, the answer to avoiding problems with math in sections (which hyperref
chokes on) is again to use \texorpdfstring
- as such:
\section{The values of \texorpdfstring{$\beta$}{TEXT} %
for which values are defined}
Here I'd much rather use something like this in the preamble:
\makeatletter
\let\oldsection\section
\renewcommand{\section}{\@ifstar
\mysectionStar%
\mysectionNoStar%
}
\newcommand{\mysectionStar}[1]{ % no two arguments here?
\typeout{AAAA}% debug
\oldsection{#1}}
\newcommand{\mysectionNoStar}[1]{ %
\typeout{BBBB}% debug
\oldsection[\getPlainText{#1}]{#1} }
\makeatother
... and avoid having to manually add \texorpdfstring
s to all the sections..
So, is there anything like this out there?
\section
doesn't seem to make sense - why would you want plain text section headings in the table of contents. A general solution would be very hard, for bookmarks most of the work is already done by\pdfstringdef
.\pdfstringdef
, will check it out. The optional argument of\section
makes sense if you're trying to force a document to build which otherwise crashes, as in say Problems building article with oolatex and hyperref - and you wouldn't want to manually change the\section
s at that point.. Cheers!