The LaTeX3 module l3msg
provides some nice functions for messaging, errors, warnings and the like and is truly flexible. The workflow is different from what we have been using for LaTex2e
packages. What are the best practices in this respect?
The way I see, some good practices (as also used in other computer languages) are:
- Wrap your own error, warning functions etc, on top of the l3msg ones.
- Create some booleans to signal errors and warnings (even if you are not using them).
- Unsure as to how best to arrange internationalizing messages, one way is to aggregate all the
\msg_new
etc in files and load them based on a language switch. This would then be similat togettext
. A second idea is to store them as token lists (strings) and use atranslator
type mechanism to translate them. A preferred way is to have a higher hierachy function:
For example instead of writing this:
\msg_set:nnnn {mypackage} { old-version }
{ LaTeX~source~files~more~than~5~year~old.~ Is~dated~
(year:#1~date:#2-#3)
the strings should be in tranlation files, marked in directories en
etc. with a format such as
__str{old-version}{en}{LaTeX~source~files~more~than~5~year~old.}
In the German file maybe something like:
__str{old-version}{LaTeX olde ...}}
Then the \msg_set
function could be modified to call:
\msg_set:nnnn {mypackage} { old-version }
{__translate{old-version}}
Partial MWE shown below (just to experiment).
\documentclass{article}
\usepackage{expl3}
\parindent0pt
\begin{document}
% Error message example
%
% simulate LaTeX2e \fmversion
\def\fmversion{2000/11/12}
\makeatletter
\ExplSyntaxOn
% create error boolean
\bool_new:N \l_mypackage_error_bool
% redirect package errors here
\cs_new_protected:Npn \mypackage_warning:nxx #1#2#3 {
\bool_set_true:N \l_mypackage_error_bool
\msg_info:nnxx { mypackage } {#1} {#2} {#3}
}
% define some error messages
\msg_set:nnnn {mypackage} { old-version }
{ LaTeX~source~files~more~than~5~year~old.~ Is~dated~(year:#1~date:#2-#3) }
{ Please~update~your~distribution~visit~ctan } %(*@\label{test}@*)
% check version number
\cs_new:Npn \mypackage_check_version:n #1 {
\exp_after:wN \l_mypackage_check_version_aux:w #1\q_stop
}
% check version number auxiliary
\cs_new:Npn \l_mypackage_check_version_aux:w #1/#2/#3\q_stop {
\int_compare:nNnTF { (\tex_year:D-#1)*12 + (\tex_month:D-#2) } > { 65 }
{ FAIL\\ \mypackage_warning:nxx {old-version} {#1} {#1/#2/#3} }
{ PASS\\ }
}
\mypackage_check_version:n \fmversion
\mypackage_check_version:n \fmtversion
\ExplSyntaxOff
\end{document}
{ some }
etc easily. Will you edit if you can and fix it a bit.