samcarter
*(For context: I'm working on a little package based on this answer https://topanswers.xyz/tex?q=8139#a7751)*
I have an expandable macro which gives a fudge factor for the current font based on a look-up table of values. If the current font is not in the look-up table (like `cmr` in the example below), I would like to return a default value (1) and issue a package warning.
I tried with `\PackageWarning`, but this seems to interfere with the expandability. Is there any way to issue a warning to the .log in this situation?
```
\documentclass[varwidth,border=1pt]{standalone}
\ExplSyntaxOn
\makeatletter
\NewExpandableDocumentCommand{ \busyPanda } { m } {
\str_case_e:nnF { \f@family } {
{cmdh}{0.785169}
{cmss}{1.16462}
{cmtt}{1.14753}
{cmvtt}{1.28199}
{cmbr}{1.03998}
}{
\PackageWarning{quack}{Font~not~in~lookup~table}
1
}
}
\makeatother
\ExplSyntaxOff
\newcommand{\bamboo}{%
\rule{\busyPanda{}\fontcharht\font`I}{\fontcharht\font`I}%
}
\begin{document}
cmr: \bamboo
\fontfamily{cmbr}
cmbr: \bamboo
\end{document}
```
Top Answer
Skillmon
# LuaTeX only
Inside of LuaTeX you can use `texio.write()` without a file target in which case the behaviour is to output to the log file (and if not in batchmode also the terminal), and to start on a new line you car use `texio.write_nl()` instead. The following uses that to set up a very simple warning macro.
```
\documentclass[varwidth,border=1pt]{standalone}
\expanded{\unexpanded{\newcommand\expandablewarning[2]}
{%
\noexpand\directlua
{%
texio.write_nl(
"\string\n Package
\unexpanded{\luaescapestring{#1}} Warning:
\unexpanded{\luaescapestring{#2}}\string\n\string\n"
)
}%
}}
\ExplSyntaxOn
\makeatletter
\NewExpandableDocumentCommand{ \busyPanda } { m } {
\str_case_e:nnF { \f@family } {
{cmdh}{0.785169}
{cmss}{1.16462}
{cmtt}{1.14753}
{cmvtt}{1.28199}
{cmbr}{1.03998}
}{
\expandablewarning{quack}{Font~not~in~lookup~table}
1
}
}
\makeatother
\ExplSyntaxOff
\newcommand{\bamboo}{%
\rule{\busyPanda{}\fontcharht\font`I}{\fontcharht\font`I}%
}
\begin{document}
cmr: \bamboo
\fontfamily{cmbr}
cmbr: \bamboo
\end{document}
```
Which results in the following log excerpt:
```none
.
.
.
LaTeX Font Info: Checking defaults for OMX/cmex/m/n on input line 34.
LaTeX Font Info: ... okay on input line 34.
LaTeX Font Info: Checking defaults for U/cmr/m/n on input line 34.
LaTeX Font Info: ... okay on input line 34.
Package quack Warning: Font not in lookup table
LaTeX Font Info: External font `cmex10' loaded for size
(Font) <7> on input line 41.
LaTeX Font Info: External font `cmex10' loaded for size
(Font) <5> on input line 41.
.
.
.
```