4

In a function I have in a package I'm working on I'm trying to add the following line:

\expandafter\newif\csname ifgre@scale@#1\endcsname%

Now, this works fine under LuaLaTeX, but the package is supposed to be compatible under both LuaLaTeX and LuaTeX and when I try to compile a document in LuaTeX, I get the following error:

! Forbidden control sequence found while scanning definition of \grechangedim.
<inserted text> 
}
<to be read again> 
\newif 
l.828           \expandafter\newif
                         \csname ifgre@scale@#1\endcsname%
? 

Is there a PlainTeX compatible way to create a new conditional within a function?

LuaLaTeX MWE:

\documentclass[11pt]{article}

\usepackage{testing}

\begin{document}
\grechangedim{test}
Hello.
\end{document}

LuaTeX MWE:

\pdfpagewidth210mm
\pdfpageheight297mm
\input testing-input.tex
\grechangedim{test}
Hello.
\bye

testing.sty:

% ------IDENTIFICATION------
\NeedsTeXFormat{LaTeX2e}[2005/12/01]
\ProvidesPackage{testing}
% For testing package code.

% ------INITIAL CODE------

% ------DECLARATION OF OPTIONS------

% ------EXECUTION OF OPTIONS------
\ProcessOptions

% ------PACKAGE LOADING------

% ------MAIN CODE------

\AtBeginDocument{}

\AtEndDocument{}

\input testing-input.tex

testing-input.tex:

\def\grechangedim#1{%
    \expandafter\newif\csname ifgre@scale@#1\endcsname%
}
1
  • Where is the luatex content here? – user31729 Sep 17 '15 at 18:45
6

The command \newif is 'outer' in plain TeX: it cannot appear inside any other macro. However, \csname newif\endcsname can appear, so you can do

\csname newif\expandafter\endcsname\csname ifgre@scale@#1\endcsname

and all will be well. This is not LuaTeX-specific: it's a general feature of working with plain.

1
  • There's a typo in your answer (\expandafer should be \expandafter) but after fixing that this works fine. Thanks. – rpspringuel Sep 17 '15 at 18:54

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.