![仅从 latex 命令获取文本(不带 latex 标签)](https://linux22.com/image/341830/%E4%BB%85%E4%BB%8E%20latex%20%E5%91%BD%E4%BB%A4%E8%8E%B7%E5%8F%96%E6%96%87%E6%9C%AC%EF%BC%88%E4%B8%8D%E5%B8%A6%20latex%20%E6%A0%87%E7%AD%BE%EF%BC%89.png)
我只需要获取命令打印的不带乳胶格式(并且不带换行符)的 ascii 文本。
我需要它自动生成pdf文档名称\hypersetup{pdftitle={<name of document>}}
在某些情况下,我可以将标题定义为\title{My \texttt{run.py} script}
但是,如果我尝试放置\hypersetup{pdftitle={\theauthor}}
(\theauthor
来自titling
包)。
这就是为什么我只需要从\theauthor
命令中提取文本。
答案1
也许这就是你正在寻找的:
\documentclass{article}
\usepackage{hyperref}
\newcommand\fauve{My \texorpdfstring{\textbf{name}}{name} is fauve}
\hypersetup{pdfauthor=\fauve}
\begin{document}
\verb+\fauve+: \fauve
\end{document}
答案2
最后,我找到了我的错误所在,我把 pdf 定义放在了\title
和\author
声明之前。
这是获得自动 pdf 适配的好方法(即使它包含 LaTeX 标签):
\title{My \textbf{Great} title\\ and subtitle}
\author{\textbsc{ME}}
\date{\today}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% PDF specificity %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\makeatletter
\hypersetup{
pdftitle={\@title},
pdfauthor={\@author}
}
\makeatother