expl3 メッセージを更新しますか?

expl3 メッセージを更新しますか?

lualatex、Linux、TeXlive 2023 を使用します。

要求されたフォントが見つからない場合はfontspec、次のように定義されたメッセージを発行します (expl3 を使用)。

\__fontspec_msg_new:nnn {font-not-found}
 {
  The font "#1" cannot be found.
 }
 {
  A font might not be found for many reasons.\\
  Check the spelling, where the font is installed etc. etc.\\\\
  When in doubt, ask someone for help!
 }

私の場合、カスタム ドキュメント クラスでは、フォントが見つからない理由は 1 つだけであり、問​​題を解決するための具体的な手順があります。これは、ユーザーによるフォントの選択が制限されているためです。そのため、上記のメッセージを再定義したいと思います。fontspec読み込み直後、フォントを検索する前に、次のようなメッセージを表示したいと思います。

\ExplSyntaxOn
\__fontspec_msg_new:nnn {font-not-found}
 {
  The font "#1" cannot be found.
 }
 {
  You need to install package "this-font-package".\\
  If your system does not allow you to install packages,\\
  then download the font package zip archive, unzip it,\\
  and place the *.otf files in the same directory as the main document.
 }
\ExplSyntaxOff

私はそれが機能するとは思っていませんでした (機能しませんでした) が、それをハッキングしようとしましたが、\__fontspec_msg_renewこれも機能しませんでした (どうやら msg_renew のようなものはないようです)。

expl3 がこれを処理できることは間違いありません。 オー、達人さん、どうやって?

答え1

を使用して\msg_set:nnnnメッセージの新しいテキストを設定することもできますが、コメントに記載されているように、おそらくこれを行うのではなく、独自のクラスまたはパッケージからエラーを発行する必要があります。

\documentclass{article}
\usepackage{fontspec}
\ExplSyntaxOn
\msg_set:nnnn {fontspec} {font-not-found}
 {
  The~font~"#1"~cannot~be~found.
 }
 {
You~need~to~install~package~"this-font-package".\\
If~your~system~does~not~allow~you~to~install~packages,\\
then~download~the~font~package~zip~archive,~unzip~it,\\
and~place~the~*.otf~files~in~the~same~directory~as~the~main~document.
 }
\ExplSyntaxOff
\setmainfont{foo.otf}
\begin{document}
\end{document}

を使用してメッセージを変更する場合は、それを実行するために\AtBeginDocumentを定義する必要があります\NewDocumentCommand

\ExplSyntaxOn
\NewDocumentCommand{\fixerror}{}{
\msg_set:nnnn {fontspec} {font-not-found}
 {
  The~font~"##1"~cannot~be~found.
 }
 {
You~need~to~install~package~"this-font-package".\\
If~your~system~does~not~allow~you~to~install~packages,\\
then~download~the~font~package~zip~archive,~unzip~it,\\
and~place~the~*.otf~files~in~the~same~directory~as~the~main~document.
 }
}
\ExplSyntaxOff
\AtBeginDocument{\fixerror}

関連情報