I am finding that I am writing more and more packages/commands for other people these days and have started writing some nice default utility commands to use. However, there is always the concern for clashes with other people's custom commands, and so I have started writing informative output to the message log and console for users to see what is happening. Below is an example of one such (fully functional and with extra \message commands) command:

    \@ifundefined{c@#1} % Check to see if counter exists
        {                                   %If not, create it and set it to 0.
        \message{The counter #1 didn't exist, so I created it and set it to 0.}
        {                                   %If so, reset to 0.
        \message{I just overwrote the counter #1, it was set to \arabic{#1} and I forced it to 0.}
        \message{Hopefully it wasn't needed anymore.}

However, for debugging purposes (both for myself and for helping others) I would like for the \message command output above to "pop out" in the message log/console in my IDE (Texstudio, if it matters) and was hoping there was a way to color or bold the text of \message. I've tried standard LaTeX color commands, which unsurprisingly didn't work. What commands can I use to modify the text output to the log/console? And if anyone has any other suggestions as to how to make these "pop" more at a visual scan, that would also be welcome (Side note: I know I could put some sort of unique string in for a find command in a text editor; this is just so I can do a quick visual scan of the end of a compile to see if any of my own messages posted and what they returned as a 'stage-one' debug).

  • 3
    Maybe using \@latex@warning{Message} and \@latex@error{SomeMessage}{Details} would help making them "pop"? (These commands are based on the LaTeX \GenericWarning and \GenericError, but you're probably better off using the @warning) – Andreas Storvik Strauman May 16 '18 at 15:28
  • 1
    I don't think you can colour log output (it is a text file after all! - you may manage to colour the console output if your terminal does that). The colours that your IDEs show are controlled alone by your IDE, there is nothing TeX can do about that. I assume that the IDE simply detects TeX's standard message format. You can format your messages as warning of error in which case I guess they would be highlighted by the IDE. ... – moewe May 16 '18 at 15:32
  • 1
    I guess there is a cause to be made that your 'I just overwrote the counter... 'messages should be warnings, the 'The counter #1 didn't exist' should not be warnings, I think. tex.stackexchange.com/q/3306/35864 and tex.stackexchange.com/q/227900/35864 may be interesting. – moewe May 16 '18 at 15:32
  • Ah, Yea I meant to color the console output, not the actual text log file. Edited to make that more clear. The "warnings" message is a good point. I'll look into that, since that's more in line with what I am thinking/doing anyway, thanks! – Jason May 16 '18 at 15:44
  • 1
    Awesome. Ill do it as soon as I can! – Andreas Storvik Strauman May 17 '18 at 10:58

I use Atom myself, and it gives me warnings and errors all the time. Turns out it comes from LaTeX Warning: SOMEWARNING on input line 123.

I use these warnings myself - especially for debug purposes. For debug purposes I use \@latex@warning{SOMEWARNING}. It pops out as a warning in Atom, and I suspect it would in most IDEs that support building LaTeX.

\@latex@warning is based on the LaTeX \GenericWarning, but to get the correct format, you're probably better off using \@latex@warning)

As @moewe points out, for use in production packages you should use \PackageWarning/\ClassWarning and \PackageError/\ClassError. Both of these also have an Info version for less serious messages.

Another debugging tool i use is to apply \meaning into this, so you have a \def\inspect#1{\@latex@warning{\string#1:\meaning#1}} which also is pretty useful.

  • 1
    If one is writing a package or class \PackageWarning and \ClassWarning might be interesting as well. There is also \GenericWarning. All of these commands also have a Info and Error version for less serious and more serious output. I would probably issue a warning for I just overwrote the counter and an info for The counter #1 didn't exist. – moewe May 17 '18 at 14:15

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.