7

When I'm writing my own private style packages, such as when developing them, I find it useful to use \typeout to help me see what I've currently created or figure out what line of code is the source of the issues (particularly when a mysterious error message is getting thrown).

Currently, I'm refractoring some old expl3 code I created back when I understood very little expl3. Throughout that code I've got things like \typeout and a judicious sprinkling of \space thrown in there to make terminal output simple and easy to read. I've come to actually like this terminal output because it helps me debug things, but I can't find anything expl3 equivalents of \typeout. The best I can find is \msg_warning:... which throws too much to the terminal.

Similarly, I like that I can concatenate \space to create larger white space on the terminal screen. Concatenating ~ doesn't work.

A third macro I've come to really appreciate when debugging and outputting to terminal is \detokenize.

It would seem that when write expl3, I should stick with expl3 macros and such. Does anyone have any suggestions about writing expl3 equivalents for:

\typeout{....}
\detokenize{....}
\space
  • \msg_term:n should be what you need. – egreg Nov 28 '14 at 20:54
6

You want \msg_term:n that expands macros in the usual way.

\RequirePackage{expl3}

\ExplSyntaxOn

\msg_term:n {Hi,~Andrew,~how~are~you?~This~message~will~automatically~
 wrap~when~reaching~a~predefined\c_space_tl limit. \\ \\
 You~can~force~a~break~and~use~\exp_not:N \tl_to_str:n
 for~showing~\tl_to_str:n{\whatever~you~\want}}

This will output

*************************************************
* Hi, Andrew, how are you? This message will automatically wrap when
* reaching a predefined limit.
* 
* You can force a break and use \tl_to_str:n for showing \whatever you \want 
*************************************************

So \msg_term:n is the analog of \typeout, while \tl_to_str:n is \detokenize; a space is \c_space_tl, which is exactly the same as \space.

There's also \msg_log:n for writing to the log file only.

  • 1
    Backslash-space is an alternative to ~ within any text that is wrapped, and can be useful when wanting to produce several spaces in a row. – Bruno Le Floch Nov 29 '14 at 1:42
5

grep is your friend:

l3kernel/l3tl.dtx:\cs_new_eq:NN \tl_to_str:n \etex_detokenize:D


l3kernel/l3tl.dtx:\tl_const:Nn \c_space_tl { ~ }

for messages if you don't like the \msg functions, probably \typeout is still your friend.

  • \c_space_tl doesn't get expanded within a \msg_ command. (I'll try to put together a simple example of what I mean). Also, after a bit of digging, I found \iow_term:x which seems to do what \terminal does: am I right? – A.Ellett Nov 28 '14 at 20:47
  • @A.Ellett \c_space_char might be more to your liking – David Carlisle Nov 28 '14 at 21:20
  • @DavidCarlisle \c_space_token? \c_space_tl doesn't get expanded because it's a token list so it's \unexpanded{ }? – Manuel Nov 28 '14 at 21:24
  • @Manuel see the OP is spoilt for choice:-) – David Carlisle Nov 28 '14 at 21:27
  • I would go for \space even in expl3 code. – Manuel Nov 28 '14 at 21:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.