expl3 renovar mensaje?

expl3 renovar mensaje?

Usando lualatex, Linux, TeXlive 2023.

Cuando fontspecno puede encontrar una fuente solicitada, emite un mensaje, definido de la siguiente manera (usando 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!
 }

En mi caso, con una clase de documento personalizada, hay exactamente una razón por la cual no se encuentra una fuente e instrucciones específicas para solucionar el problema. Esto se debe a que la elección de fuentes por parte del usuario es limitada. Por eso quiero redefinir el mensaje anterior. Inmediatamente después de fontspeccargar, pero antes de buscar fuentes, quiero algo como esto:

\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

No esperaba que funcionara (no funcionó), pero intenté hackearlo con\__fontspec_msg_renew lo cual tampoco funciona (aparentemente no existe algo como msg_renew).

Sin duda, expl3 puede manejar esto. Oh gurús, ¿cómo?

Respuesta1

Puede utilizar \msg_set:nnnnpara establecer un nuevo texto para el mensaje, pero como se menciona en los comentarios, probablemente no debería hacer esto, sino emitir un error desde su propia clase o paquete.

\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}

Si desea que el mensaje cambie usando, \AtBeginDocumentdebe definir un \NewDocumentCommandpara hacerlo:

\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}

información relacionada