2

By means of the l3msg package you can create nice messages.

Redirecting from one message-class to another (e.g., turning error-messages into warning-messages) is possible as well.

How can I redirect the module whose message is to be displayed?

E.g., when using l3keys/\keyval_parse:nnn/\keys_set:nn and providing a blank key name, you get the message \LaTeX3 error: Blank key name in key-value input on line ...

With some macros of mine, in this situation I'd like another message-text to be displayed instead.

A message-text that is defined in my module and that names both my module and the macro of mine because this way identifying the macro-call on user-level which triggers the processing-chain which in the end leads to the error-message is more easy.



At first I assumed I could do something like this:

\group_begin:
\msg_set:nnn { LaTeX } { kernel/blank-key-name }  { My additional remarks. Blank~key~name~in~key-value~input~\msg_line_context: }
\prop_put:Nnn \g_msg_module_name_prop { LaTeX } { MYMODULE }
\keyval_parse:nnn{\MYMODULE_PrintKey:n}{\MYMODULE_PrintKeyAndValue:nn}{a=b, a=, =b}
\group_end:

But it doesn't work out: With , =b I still get
\LaTeX3 error: Blank key name in key-value input on line...
instead of
! Package MYMODULE Error: My additional remarks. Blank key name in key-value input on line... .

It seems that this is due to l3keys using \__kernel_msg_expandable_error:nn instead of \msg_error:nn for raising the message—using \msg_error:nn leads to the desired error-message-text:

\ExplSyntaxOn
\tex_scrollmode:D
\documentclass{article}

\cs_new:Nn \MYMODULE_PrintKey:n {\MYMODULE_PrintKeyAndValue:nn {#1}{None}}
\cs_new:Nn \MYMODULE_PrintKeyAndValue:nn {Key: #1. Value: #2.}

\begin{document}

\tex_message:D{^^J^^J------------------------------^^J
               Error-message~as~usual,~raised~by~\token_to_str:N\keyval_parse:nnn:\space :^^J
               ------------------------------^^J^^J}

\keyval_parse:nnn{\MYMODULE_PrintKey:n}{\MYMODULE_PrintKeyAndValue:nn}{, =b}

\tex_message:D{^^J^^J------------------------------^^J
               Error-message~as~usual,~raised~by~\token_to_str:N\msg_error:nn\space :^^J
               ------------------------------^^J^^J}

\msg_error:nn { LaTeX } { kernel/blank-key-name }

\group_begin:

\msg_set:nnn { LaTeX } { kernel/blank-key-name }  { MY~ADDITIONAL~REMARKS.~Blank~key~name~in~key-value~input~\msg_line_context: }
\prop_put:Nnn \g_msg_module_name_prop { LaTeX } { MYMODULE }

\tex_message:D{^^J^^J------------------------------^^J
               Although~the~message-text~is~changed,~via~\token_to_str:N\keyval_parse:nnn\space~you~still~get~the~error-message~as~usual...^^J
               ------------------------------^^J^^J}

\keyval_parse:nnn{\MYMODULE_PrintKey:n}{\MYMODULE_PrintKeyAndValue:nn}{, =b}

\tex_message:D{^^J^^J------------------------------^^J
               ...while~via~\token_to_str:N\msg_error:nn\space~you~get~the~desired~message-text:^^J
               ------------------------------^^J^^J}

\msg_error:nn { LaTeX } { kernel/blank-key-name }

\group_end:

\end{document}

Console-output:

prompt$ pdflatex test.tex
This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./test.tex
LaTeX2e <2020-10-01> patch level 4
L3 programming layer <2021-02-18>
(/usr/local/texlive/2020/texmf-dist/tex/latex/base/article.cls
Document Class: article 2020/04/10 v1.4m Standard LaTeX document class
(/usr/local/texlive/2020/texmf-dist/tex/latex/base/size10.clo))
(/usr/local/texlive/2020/texmf-dist/tex/latex/l3backend/l3backend-pdftex.def)
(./test.aux)


------------------------------
Error-message as usual, raised by \keyval_parse:nnn: :
------------------------------

! Undefined control sequence.
<argument> \LaTeX3 error: 
                           Blank key name in key-value input on line 14
l.14 ...ey:n}{\MYMODULE_PrintKeyAndValue:nn}{, =b}
                                                  



------------------------------
Error-message as usual, raised by \msg_error:nn :
------------------------------


! LaTeX3 Error: Blank key name in key-value input on line 20

Type <return> to continue.
 ...                                              
                                                  
l.20 ...ror:nn { LaTeX } { kernel/blank-key-name }
                                                  



------------------------------
Although the message-text is changed, via \keyval_parse:nnn you still get the e
rror-message as usual...
------------------------------

! Undefined control sequence.
<argument> \LaTeX3 error: 
                           MY ADDITIONAL REMARKS. Blank key name in key-valu...
l.31 ...ey:n}{\MYMODULE_PrintKeyAndValue:nn}{, =b}
                                                  



------------------------------
...while via \msg_error:nn you get the desired message-text:
------------------------------


! MYMODULE Error: MY ADDITIONAL REMARKS. Blank key name in key-value input on
(MYMODULE)        line 37

Type <return> to continue.
 ...                                              
                                                  
l.37 ...ror:nn { LaTeX } { kernel/blank-key-name }
                                                  
(./test.aux) )
(see the transcript file for additional information)
No pages of output.
Transcript written on test.log.

This in turn leads to the question why the regular interface for messages is bypassed with packages like l3keys?

Please don't understand my questions as "work requests", but rather as attempts to broaden my understanding of the current state of affairs. Especially since my concern is more of a nitpicking/academic nature anyway - what do we have \errorcontextlines=... for if not for tracing to the initiating user-level-macro/top-level-macro the chain of processing which leads to an error-message? :-)

3
  • Question: In what sense "redirect"? Aren't module and message just namespaces? Doesn't \msg_set:... set a message for a module? (like \renewcommand?) If I set this: \msg_set:nnn { LaTeX } { kernel/blank-key-name } { MyMessage - Blank~key~name~in~key-value~input~\msg_line_context: } and then issue this \msg_error:nn { LaTeX } { kernel/blank-key-name }, I get this in the log: ! LaTeX3 Error: MyMessage-Blank key name in key-value input on line 109. You may have to intercept/redefine the line where the message issues from, maybe, if kernel checks are before user checks+set.
    – Cicada
    Aug 15, 2021 at 8:24
  • @Cicada When calling a user-level-macro from my module is done in a way which leads to an error, then both that user-level-macro and my module should be named in the error-message in order to ease up finding the place in the source-code where the error was made. The info "\LaTeX3 error:` coming from code underlying my user-level-macro is not too useful here. It would be better, instead, to have displayed a "Module: MyModule error:" or "Package: MyPackage error:". This way the macro whose call initiated the processing-chain leading to the error-message can be identified more easy. But it is ... Aug 15, 2021 at 20:44
  • .. a moot/nitpcking point: After all, the experienced user can do \errorcontextlines=... and find out about the macro-processing-chain that leads to triggering the error. Aug 15, 2021 at 20:45

1 Answer 1

2

The message system doesn't allow you to 'change the name' of the message/module, as they are the unique identifier of the message itself. However, you could (ab)use the fact that the internal module name and the printed name do not have to agree, viz.

\ExplSyntaxOn
\prop_new:N \l_msg_module_name_prop
\prop_set_eq:NN \l_msg_module_name_prop \g_msg_module_name_prop
\prop_gput:Nnn \g_msg_module_name_prop { LaTeX } { demo }
\keys_set:nn { foo } { bar }
\prop_gset_eq:NN \g_msg_module_name_prop \l_msg_module_name_prop
\ExplSyntaxOff

On the question of non-redirectable messages, there was an original design decision to exempt the kernel from redirection. The idea was that whilst for a package it might be reasonable to allow messages to be redirected or entirely suppressed, that was less likely with material from the kernel, which is almost always of a programmatic nature. However, the issue then becomes one of deciding where that line lies. We are therefore re-working this area to stick just to \msg_error:nn(nn), etc.: there are still some details to finalise but this should be updated soon.

3
  • My question is about the following: Can I "tell" the message-system to use a certain message defined in my module instead of another specific message that is defined elsewhere. Seems there is no interface for that which includes messages raised, e.g., via \__kernel_msg_expandable_error:nn. This in turn leads to the question why the regular interface for messages is bypassed with packages like l3keys. Aug 15, 2021 at 19:17
  • @UlrichDiez The original idea was that kernel level messages are 'non-maskable': they are deliberately set up to bypass any redirection. We've re-thought that but at present have not merged some changes - it's on my to-do list and I'll move it up as it's come up here. Would a release sometime later this week be OK?
    – Joseph Wright
    Aug 15, 2021 at 19:54
  • Of course, that would be more than okay. :-) It would also be okay if nothing was done at all: At the end of the day, I don't like to have my questions and comments understood as "work requests", but rather as attempts to broaden my understanding of the current state of affairs. :-) After all, the more things in the kernel you make changeable by users, the more "places" you create where non-intended user-input can cause problems. Especially since my concern is more of a nitpicking/academic nature anyway - what do we have \errorcontextlines=... for? :-) Aug 15, 2021 at 20:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .