0

I'm trying to define an environment that is conditionally complied in lualatex. The two solutions I've tried are the following:

\documentclass{article}

\newenvironment{test}{\ifx\X y \\ }{\else \\ \fi}

\begin{document}

\begin{test}
This should not be seen without the varible X set to y.
\end{test}

this should always be seen.

\end{document}

The following also does not work:

\newenvironment{test}{\ifdef{\something}{ }{ }{}}

Nor does:

\newenvironment{text}{\ifdef \\ }{\else \\ \fi}

Whereas all of the above do work in both pdftex and lualatex if I manually replace the "\begin{test}" and "\end{test}" in my code with their definitions.

What gives? Does LaTeX not let you use \ifdef and similar constructs within user-defined environments/definitions? Is there any way to get this to work?

  • 4
    Welcome to TeX.SE! You can use the comment package to do something like that. Your approach doesn't work because when TeX processes a conditional it will look for an "explicit" \else or \fi, which are not there. For the \else and \fi to appear you'd have to expand the \end{test} before. – Phelype Oleinik Feb 11 at 17:19
  • Try with this code. Comment/uncomment the \def\X{y} component. – Werner Feb 13 at 4:19

Your Answer

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

Browse other questions tagged or ask your own question.