# Creating a ConTeXt/LaTeX hybrid module

I have a simple titlepage, which I want to make available for ConTeXt- as well as LaTeX users. Each should just type \usemodule[myTitlepage], or \usepackage{myTitlepage}, respectively.

I want to do this by determining if LaTeX is used, and if so, define all used ConTeXt-macros to their LaTeX equivalents, so that the titlepage can be written in ConTeXt, similar to this:

\ifLaTeX
\newcommand{\starttikzpicture}[1]{\begin{tikzpicture}[#1]}
\newcommand{\stopttikzpicture}   {\end  {tikzpicture}    }
\newcommand{\crlf}{\\}
...
\else
\doConTeXtRelatedStuff
\fi

\starttikzpicture[scale=3]
\node [text centered] {it works! \crlf or does it?};
\stoptikzpicture


What do I use instead of the pseudocode \ifLaTeX and will the whole idea likely work?

-

You can check for some macros that is defined only in LaTeX or ConTeXt. For example, ConTeXt defines \contextformat and \contextversion which hopefully should not be defined by a LaTeX package. Similarly LaTeX defines \documentclass which is not defined by any ConTeXt module.
However, a better solution might be to let kpse choose the format for you. Create a file called mytitlepage.tex in $TEXMF/tex/genereic/.... that contains the common code. Then create a file mytitlepage.sty in $TEXMF/tex/latex/... that contains latex specific code and loads mytitlepage.tex and create a file t-mytitlepage.(tex|mkii|mkiv|lua) in \$TEXMF/tex/context/third/... that contains ConTeXt specific code and loads mytitlepage.tex. This way, the right file is chosen depending on the format.
That's the approach pgf takes: I'd been meaning to post something very similar :-) –  Joseph Wright Sep 12 '11 at 5:58
That seems to be a very standard-compliant way of doing it, but it means that I have to develop an install script that puts the files into the user’s texmf tree, instead of simply telling them to drop a single .tex file next to their document in order to install it. But then, I could as well just let the script generate the appropriate file: ./make_titlepage.py latex. A “drop-in” module would be best. –  flying sheep Sep 12 '11 at 10:07