为 CV 创建包,并单独提供选项

为 CV 创建包,并单独提供选项

我用 latex 写了简历,想与全世界分享,但现在代码太乱了。我想写一个包,这样用户就可以

\addjob{1}{Job title 1}
\addshortdesc{1}{short description}
\addstartdate{1}{start date}
\addenddate{1}{end date}
\addaccomplishment{1}{accomplisment one}
\addaccomplishment{1}{accomplisment two}
\addaccomplishment{1}{accomplisment three}

\addjob{2}{Job title 2}
\addshortdesc{2}{short description}
\addstartdate{2}{start date}
\addenddate{2}{end date}
\addaccomplishment{2}{accomplisment one}
\addaccomplishment{2}{accomplisment two}

我尝试谷歌搜索,但找不到创建我想要的东西的方法。只是通常的新命令定义,需要立即输入所有内容。

可以这样做吗?我从来没有做过这样的事。谢谢!

答案1

最重要的是,一切都归结为将内容保存在宏中并在以后使用它们。这个基本想法可能是这样的:

\documentclass{article}

\makeatletter
\newcommand*{\job@list}{}
\newcommand*{\addjob}[5]{% \addjob{label}{title}{start date}{end date}{description}
   \@namedef{job@#1}{#2}%
   \@namedef{job@#1@accomplishment}{}%
   \g@addto@macro\job@list{{#1}}%
   \@namedef{job@#1@startdate}{#3}%
   \@namedef{job@#1@enddate}{#4}%
   \@namedef{job@#1@desc}{#5}%
}
\newcommand*{\addaccomplishment}[2]{%
   \expandafter\g@addto@macro\csname job@#1@accomplishment\endcsname{{#2}}%
}
\newcommand*{\printjobs}{%
   \edef\@tempa{\noexpand\@tfor\noexpand\x:=\job@list}\@tempa
   \do{%
   \par\noindent
   \textbf{\@nameuse{job@\x}}
   (\@nameuse{job@\x @startdate}--\@nameuse{job@\x @enddate}):
   \@nameuse{job@\x @desc}
   \begin{itemize}
   \expandafter\expandafter\expandafter\print@accomplishments\csname job@\x @accomplishment\endcsname\relax
   \end{itemize}
   }%
}
\newcommand*{\print@accomplishments}[1]{%
   \ifx#1\relax\else\item#1\expandafter\print@accomplishments\fi
}
\makeatother

\usepackage{hyperref}% for the example

\addjob{1}{Job title 1}{1.1.1900}{2.2.1900}{short description}
\addaccomplishment{1}{accomplishment one}
\addaccomplishment{1}{accomplishment two}
\addaccomplishment{1}{accomplishment \href{tex.stackexchange.com}{three}}

\addjob{2}{Job title 2}{3.3.1900}{4.4.1901}{short description}
\addaccomplishment{2}{accomplishment \textbf{one}}
\addaccomplishment{2}{accomplishment two}

\begin{document}

\printjobs

\end{document}

在此处输入图片描述

当然,为了使这个软件包合理,你必须引入很多改进,例如检查你没有两次使用相同的工作“标签”,在尝试打印之前检查日期或成就是否存在,防止参数中出现不可扩展的内容,等等……这些都留给读者作为练习:-)

相关内容