![小于字符串比较,例如 \ifstrequal](https://linux22.com/image/357656/%E5%B0%8F%E4%BA%8E%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%AF%94%E8%BE%83%EF%BC%8C%E4%BE%8B%E5%A6%82%20%5Cifstrequal.png)
有没有办法获得\ifstrlessthan
类似于电子工具箱\ifstrequal
我想要做类似的事情
\ifstrlessthan{\creationdate}{2017-01-01}%
{Old company name}{New company name}
答案1
\documentclass{article}
\usepackage{pdftexcmds}
\newcommand{\companyNameChangeDate}{2016-01-01}
\newcommand{\creationDate}{2017-01-01}
\begin{document}
\makeatletter
\ifcase\pdf@strcmp{\creationDate}{\companyNameChangeDate} new company name \or new company name \else old company name \fi
\makeatother
\end{document}
印刷新公司名称
答案2
如果删除连字符,您将得到可以比较的数字:
\documentclass{article}
% assume dates are in ISO format YYYY-MM-DD
\makeatletter
\newcommand{\ifdateearlierTF}[2]{%
\ifnum\@date@to@number{#1}<\@date@to@number{#2}
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
}
\def\@date@to@number#1{\expandafter\@date@to@number@aux\romannumeral-`Q#1\@nil}
\def\@date@to@number@aux#1-#2-#3\@nil{#1#2#3}
\makeatother
\begin{document}
\newcommand{\creationdate}{2016-01-01}
\ifdateearlierTF{\creationdate}{2017-01-01}{Old company name}{New company name}
\renewcommand{\creationdate}{2017-06-30}
\ifdateearlierTF{\creationdate}{2017-01-01}{Old company name}{New company name}
\end{document}