如何解决有没有办法从包含乳胶名称的宏中提取缩写?
我正在编写一个cv类,并且想要提取cvauthor的缩写。我在.cls文件中声明了一个宏,该宏应包含作者名称,获取它之后,我想根据某个分隔符对其进行拆分,并获取每个子字符串的第一个字母。这是我所做的,但仍然收到错误消息。
myclass.cls\ProvidesClass{resumecv}[2020/09/12 CV class]
\LoadClass{article}
\NeedsTeXFormat{LaTeX2e}
\RequirePackage{xstring}
\RequirePackage{soul}
\RequirePackage[absolute,overlay]{textpos}
\sodef\myspace{}{.1em}{0.5em plus0.5em}{2em plus.1em minus.1em} % User-defined letter spacing
\newcommand{\cvauthor}[1]{\renewcommand{\cvauthor}{\textsc{\myspace{#1}}}}
\newcommand{\FirstInitial}{}
\newcommand{\SecondInitial}{}
\newcommand*{\ExtractInitials}[1]{%
\StrRemoveBraces{#1}[\FirstInit]%
\StrChar{\FirstInit}{1}[\FirstInit]
\renewcommand{\FirstInitial}{\FirstInit}
\StrBehind{#1}{ }[\second]%
\StrRemoveBraces{\second}[\SecondInit]%
\StrChar{\SecondInit}{1}[\SecondInitial]
}
\newcommand*{\makeskeleton}{
\begin{textblock}{20}(0,0)
\ifthenelse{\equal{\cvauthor}{}}{}{
%\Huge\textcolor{darkYellow}{\textbf{\cvauthor}}
% \renewcommand{\name}{\cvauthor}
% \name
\ExtractInitials{\cvauthor}
\FirstInitial
\SecondInitial
}
\end{textblock}
}
我的简历
\documentclass[a4paper,11pt]{myclass}
\cvauthor{John Smith} %%% whant to extract J and S
\begin{document}
\makeskeleton
\end{document}
错误
! Use of \TP@textblock doesn't match its definition.
\text@command #1->\def \reserved@a {
#1}\ifx \reserved@a \@empty \let \check@...
l.5 \makeskeleton
?
需要别人的帮助。
解决方法
-
ifthen
包裹丢失 -
\ExtractInitials
失败,因为\cvauthor
使用所有格式(例如小写字母等)保存名称。一个简单的解决方法是定义一个仅保存纯名称的宏 -
请记住,您的
\ExtractInitials
在许多情况下都会失败:两个以上的名称部分(带前缀的名称等)。不要重新发明轮子,而要看看biblatex,它很擅长解析各种名称
\ProvidesClass{myclass}[2020/09/12 CV class]
\LoadClass{article}
\NeedsTeXFormat{LaTeX2e}
\RequirePackage{xstring}
\RequirePackage{soul}
\RequirePackage[absolute,overlay]{textpos}
\RequirePackage{ifthen}
\sodef\myspace{}{.1em}{0.5em plus0.5em}{2em plus.1em minus.1em} % User-defined letter spacing
\newcommand{\cvauthor}[1]{\newcommand{\mycvauthor}{#1}\renewcommand{\cvauthor}{\textsc{\myspace{#1}}}}
\newcommand{\FirstInitial}{}
\newcommand{\SecondInitial}{}
\newcommand*{\ExtractInitials}[1]{%
\StrRemoveBraces{#1}[\FirstInit]%
\StrChar{\FirstInit}{1}[\FirstInit]
\renewcommand{\FirstInitial}{\FirstInit}
\StrBehind{#1}{ }[\second]%
\StrRemoveBraces{\second}[\SecondInit]%
\StrChar{\SecondInit}{1}[\SecondInitial]
}
\newcommand*{\makeskeleton}{
\begin{textblock}{20}(0,0)
\ifthenelse{\equal{\cvauthor}{}}{}{
%\Huge\textcolor{darkYellow}{\textbf{\cvauthor}}
% \renewcommand{\name}{\cvauthor}
% \name
\ExtractInitials{\mycvauthor}
\FirstInitial
\SecondInitial
}
\end{textblock}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。