0

I need to get only the ascii text that a command print without latex formating (and also without linebreak).

I need it to automatically generate the pdf document name in \hypersetup{pdftitle={<name of document>}}

In some cases, I can define the title as \title{My \texttt{run.py} script} but, if I try to put \hypersetup{pdftitle={\theauthor}} (\theauthor came frome titling package).

That’s why I need to only extract text from the \theauthor command.

  • This question is very unclear to me. If you define something like \newcommand\fauve{My name is fauve}, then you can put \fauve in lots of places: \documentclass{article} \newcommand\fauve{My name is fauve} \usepackage{hyperref} \hypersetup{pdfauthor=\fauve} \begin{document} \verb+\fauve+: \fauve \end{document}.... – jon Oct 3 '16 at 3:19
  • Yes, but if i defined \newcommand\fauve{The \textbb{Greath} \tiny{and} \emph{popular} \bsc{Fauve}} I can’t put the \fauve command on pdfauthor field like \hypersetup{pdfauthor=\fauve}. It will fail. I need to extract only the text that the \fauve command print. I need to only get “The Greath and popular Fauve”, without TeX macros. – fauve Oct 5 '16 at 13:03
  • There is a macro called \texorpdfstring{<TeX>}{<PDF>} from hyperref.... – jon Oct 5 '16 at 18:38
0

Perhaps this is what you are looking for:

\documentclass{article} 
\usepackage{hyperref}
\newcommand\fauve{My \texorpdfstring{\textbf{name}}{name} is fauve} 
\hypersetup{pdfauthor=\fauve}
\begin{document}
\verb+\fauve+: \fauve                                                   
\end{document}
  • It’s a begining of a solution but it isn’t satisfying. In some cases, the \title or the \name is generated by another commands… that’s why I realy need to extract text. – fauve Oct 5 '16 at 21:04
  • I'm sorry, but your comments are too vague to be of much help to me. What other 'commands'? Generate the command properly would be my advice. That's what \texorpdfstring is specifically designed to do. If something is generating foo \textbf{bar} baz, why can't it generate foo \texorpdfstring{\textbf{bar}}{bar} baz? Or, if you want to 'extract' text, preprocess it with a language that is designed to manipulate text in that way and use TeX for the typesetting. – jon Oct 6 '16 at 2:08
  • This kind of question would benefit from being edited to include a minimal example (or see here). – jon Oct 6 '16 at 2:10
0

Finaly, I find where I had a mistake, I put the pdf definitions before the \title and \author declarations.

This is the good way to obtain automatic pdf adaptation (also if it contain LaTeX tag):

\title{My \textbf{Great} title\\ and subtitle}
\author{\textbsc{ME}}
\date{\today}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                       PDF specificity                           %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\makeatletter
  \hypersetup{
    pdftitle={\@title},
    pdfauthor={\@author}
  }
\makeatother

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.