0

what could be the way for creating an environment from within a custom command. For example, something like this :

 \NewDocumentCommand\mynewblock{m m m}{% pseudo code : % custom environment here with #1 corresponding to the name, #2 to the code "before" and #3 to the code after. } 

At first look, it may seem clumsy to do so, because a \NewDocumentEnvironment command allows to do this stuff ; but, for me, it may be useful indeed to hide the environment command to users... Thanks a lot.

6
  • 3
    The reason just to hide something from the user seems a bit odd, but you can simply do \NewDocumentCommand\mynewblock{m m m}{\NewDocumentEnvironment{#1}{}{#2}{#3}}. Commented Mar 5 at 7:23
  • 1
    Seems these days everybody wants to hide things from people. What is your reason? Commented Mar 5 at 9:27
  • 1
    @Skillmon How about \NewDocumentCommand\mynewblock{m}{\NewDocumentEnvironment{#1}{}}? Commented Mar 5 at 9:28
  • Non sense, because people able to understand what mean \NewDocumentEnvironment also can figure out what is \NewDocumentCommand or similar command. But user is usually lazy to investigate what is in a \input, a package or a document class (in increasing order). Make the environment externally to the document. Commented Mar 5 at 9:36
  • @UlrichDiez for \NewDocumentCommand and friends currying is discouraged (also I expect OP to actually put more code inside that definition). Commented Mar 5 at 9:44

1 Answer 1

2

My hunch is that you want to provide users with the possibility of defining their own “blocks” based on a common design. So you may want to have

  • some fixed initial code
  • code provided by the user
  • some fixed final code

both in the “begin” and “end” parts of the block.

\NewDocumentCommand{\NewBlock}{mmmm}{% % #1 = block name, #2 = list of argument types % #3 = begin part, #4 = end part \NewDocumentEnvironment{#1}{#2}{% %<fixed pre code for the begin part #3% %<fixed post code for the begin part }{% %<fixed pre code for the end part #4% %<fixed post code for the end part }% } 

A user will do, for instance,

\NewBlock{foo}{m}{AAA#1BBB}{CCC#1DDD} 

so to be able to call

\begin{foo}{x} Something here \end{foo} 

However, nothing can prohibit users to employ `\NewDocumentEnvironment themselves.

1
  • that's exactly it! Thanks to all of you! Commented Mar 5 at 14:42

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.