On 11/17/2014 04:57 PM, Bruce Momjian wrote:
On Mon, Nov 17, 2014 at 04:41:37PM -0500, Scott Kostyshak wrote:
On Mon, Nov 17, 2014 at 3:44 PM, Bruce Momjian <br...@momjian.us> wrote:
I know I can use Insert/File/Child Document to insert a LyX document
into an existing LyX document.  Is there any way to _conditionally_
include the document based on a TeX define, e.g.:

         \ifx \employer \include{/presentations/employer/head_bumper} \fi

but if you put this in a TeX red block, it doesn't work as \include must
be processed by LyX.

I would like to do this so I can define a TeX variable in my LaTeX
preamble and have it control the addition of slides.
Would a branch do what you want?
Yeah, thank you.  While I don't know how to activate/deactivate the
branch based on a define, it does give me a simple way to turn stuff
on/off.  I have been with LyX for 15 years and it never ceases to amaze
me.

There are some other options. The simplest is to do it this way:

PUT IN ERT: \ifx\employer\undefined\relax\else[\ERT]

...now enter a LyX include box...or any other LyX content...

PUT IN ERT: \fi

This is an extremely powerful construct.

Second, it is possible to use LyX layout to modify how branches are output. E.g., you could do this in local layout:

Format 41
InsetLayout Branch:IfEmployer
LatexType Command
LatexName ifemployer
Preamble
\newcommand\ifemployer[1]{\ifx\employer\undefined\relax\else #1\fi}
EndPreamble
End

Now if you define a branch called "IfEmployer" and activate it, it'll give you LaTeX output as:

\ifemployer{this is the content.}

and that will be included or not conditionally on whether \employer is defined.

Alternatively, since a branch is obviously overkill here, you can define it as a custom inset:

Format 41
InsetLayout Flex:IfEmployer
LatexType Command
LatexName ifemployer
Decoration Classic
LabelString IfEmployer
Preamble
\newcommand\ifemployer[1]{\ifx\employer\undefined\relax\else #1\fi}
EndPreamble
End

And then you get the same output. You could also do it as an environment, if you preferred.

Richard

Reply via email to