7

So I have defined an environment {sseqpage} where the body of the environment consists of options to control the appearance of an image. If no body is present, then the image can still be displayed just fine. Thus, I have defined a command that is shorthand for a copy of my environment with empty body \begin{sseqpage}[#1]\end{sseqpage}.

I am now tempted to define the command to check whether it is being used as an environment as follows:

\def\sseqpage{%
    \def\sseq@temp{sseqpage}%
    \ifx\@currenvir\sseq@temp
        \@xp\sseqpage@environmentcase % we're being used as an environment
    \else
        \@xp\sseqpage@commandcase
    \fi
}

Note for instance that tikz could use shenanigans like this to make \tikz and \begin{tikz} ... \end{tikz} work, rather than calling the environment form {tikzpicture}.

What are the drawbacks of doing this?

  • 3
    Such tricks are done by beamer; avoid it. – egreg Nov 10 '17 at 23:09
  • I wouldn't do it because it might get confusing to use and maintain at some point. Are you the only one who will use that? – Skillmon Nov 10 '17 at 23:16
  • No, this is for a package. There is a concern that other people could suffer for my poor decision making. – Hood Chatham Nov 10 '17 at 23:19
  • 1
    By the way, \tikz...; does \begin{tikzpicture}...;\end{tikzpicture} – egreg Nov 10 '17 at 23:27
  • 1
    technically it would probably work, but I think it would be confusing to humans – David Carlisle Nov 10 '17 at 23:27
5

While it's technically possible, this breaks the documented latex syntax (or is the documented syntax, depending on details that are not clear).

LaTeX documents that any command may be used as an environment so

\begin{small}...\end{small}

acts like

{\small ...}

even though there is no specific small environment defined.

Similarly if you have defined a command

\newcommand\sseqpage[1][foo]{....}

then that already supports any of the following

 \sseqpage
 \sseqpage[zzz]
 \begin{sseqpage}...\end{sseqpage}
 \begin{sseqpage}[zzz]...\end{sseqpage}

Your definition sketch makes \sseqpage act differently if it is in the scope of a sseqpage environment which in itself is not necessarily a bad thing (enumerate acts differently if it is in the scope of enumerate for example), but your coding hints that the syntax of the two \...case commands may be different which would make the syntax of \ssseqpage context dependent which is likely to be confusing and doesn't really follow latex syntax style.

  • For the record, my plan was to make the nonenvironment version to behave the same as an empty environment, so that \sseqpage[options] is the same as \begin{sseqpage}[options]\end{sseqpage}. I didn't do this because of the your advice not to. – Hood Chatham Sep 11 '18 at 13:48

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.