小于字符串比较,例如 \ifstrequal

小于字符串比较,例如 \ifstrequal

有没有办法获得\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}

在此处输入图片描述

相关内容