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?

New contributor
Nathan BeDell is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • 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

Nathan BeDell is a new contributor. Be nice, and check out our Code of Conduct.

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.