这是一个简单的例子。如果我有 ISBN-13 号码的前 12 位数字。
\documentclass[12pt]{report} \parskip=12pt
\def\ISBNnumber{978-618-5645-08}
\pagestyle{empty}
\begin{document}
If I have a 12-digit ISBN-13 number.
\ISBNnumber
For this ISBN number check number is 3.
Is there a way to automatically calculate this number and
add it at the end so that I have a complete ISBN number
with all 13 digits, such as this number below.
978-618-5645-08-3
\end{document}
如何创建一个新命令来计算校验码,并将其添加到末尾,以便我们获得完整的 ISBN-13。如果有人知道这个问题的答案,请帮忙并提供一个例子。
答案1
这是数字的简单加权和
https://isbn-information.com/check-digit-for-the-13-digit-isbn.html
\documentclass{article}
\newcount\isbncheck
\def\zz#1{#1-\zzz#1}
\def\zzz#1#2#3{\isbncheck=\numexpr#1+3*#2+#3\relax\zzzb}
\def\zzzb#1#2#3#4#5#6#7#8#9{\advance\isbncheck\numexpr3*(#1+#3+#5+#7+#9)+#2+#4+#6+#8\relax\zzzc}
\def\zzzc{%
\isbncheck=\numexpr10-\isbncheck+10*(\isbncheck/10)\relax
\ifnum\isbncheck>9 \advance\isbncheck-10\relax\fi
\the\isbncheck
}
\begin{document}
If I have a 12-digit ISBN-13 number.
For this ISBN number check number is 3.
Is there a way to automatically calculate this number and
add it at the end so that I have a complete ISBN number
with all 13 digits, such as this number below.
\zz{978186197271}
978-618-5645-08-3
\zz{978618564508}
\end{document}