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

내 경우에는 사용자 정의 문서 클래스를 사용하면 글꼴을 찾을 수 없는 이유가 정확히 하나 있고 문제를 해결하기 위한 구체적인 지침이 있습니다. 이는 사용자의 글꼴 선택이 제한되어 있기 때문입니다. 그래서 나는 위의 메시지를 다시 정의하고 싶다. 로드 직후 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}

관련 정보