Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

\newenvironment with optional arguments doesn't work

36 views
Skip to first unread message

Antis Lathoi

unread,
Mar 6, 2010, 9:36:45 PM3/6/10
to
Hello,
I'm trying to define a new latex environment with the following
characteristics:

1) a verse like environment
2) with a variable right margin, to prevent certain linebreaks
3) the env should have one optional argument that increases or
decreases the right margin
4) the default value of this argument is 0pt, i.e. no modification of
margins
5) everything within this env is bold

margin manipulation is provided by the "changepage" package. Its
"adjustwidth" environment takes two required length arguments:

\begin{adjustwidth}{hleftmargini}{hrightmargini}

A positive length value will increase the relevant margin (shortening
the text
lines) while a negative length value will decrease the margin
(lengthening text
lines).

So I tried the following:

\newenvironment{varioquote}[1][0pt]{\begin{quote}%
\begin{adjustwidth*}{0pt}{#1}\bfseries}%
{\end{adjustwidth*}%
\end{quote}}

Yet, when I say:

\begin{varioquote}{-2em}
TEXT TEXT...
\end{varioquote}

in order to reduce the right margin by 2em, this does not work;
instead "-2em" is printed our literally (not recognized as an argument
to the environment)! What is wrong with my definition?

Thanks,

Antis.

Ulrich M. Schwarz

unread,
Mar 7, 2010, 2:03:51 AM3/7/10
to
On Sun, 07 Mar 2010 03:36:45 +0100, Antis Lathoi <antis....@gmail.com>
wrote:

> Hello,
> I'm trying to define a new latex environment with the following
> characteristics:

[...]


> Yet, when I say:
>
> \begin{varioquote}{-2em}
> TEXT TEXT...
> \end{varioquote}
>
> in order to reduce the right margin by 2em, this does not work;
> instead "-2em" is printed our literally (not recognized as an argument
> to the environment)! What is wrong with my definition?

I guess the definition is fine, but optional args don't have curlies.
Without having tried, I'd guess that
\begin{varioquote}[-2em]
will work just fine.

HTH
Ulrich

Antis Lathoi

unread,
Mar 7, 2010, 9:32:09 AM3/7/10
to
On 7 Mrz., 08:03, "Ulrich M. Schwarz" <brother...@gmx.net> wrote:
> On Sun, 07 Mar 2010 03:36:45 +0100, Antis Lathoi <antis.lat...@gmail.com>  

> wrote:
>
>
>
> > Hello,
> > I'm trying to define a new latex environment with the following
> > characteristics:
> [...]
> > Yet, when I say:
>
> > \begin{varioquote}{-2em}
> > TEXT TEXT...
> > \end{varioquote}
>
> > in order to reduce the right margin by 2em, this does not work;
> > instead "-2em" is printed our literally (not recognized as an argument
> > to the environment)! What is wrong with my definition?
>
> I guess the definition is fine, but optional args don't have curlies.  
> Without having tried, I'd guess that
> \begin{varioquote}[-2em]
> will work just fine.

Ah! yes indeed, that was the problem: options to newly defined
environments do go in brackets!
I was misled by the tabular environment (and its options in curlies).

Thanks for your help!

Antis

Ulrich M. Schwarz

unread,
Mar 7, 2010, 1:58:55 PM3/7/10
to
On Sun, 07 Mar 2010 15:32:09 +0100, Antis Lathoi <antis....@gmail.com>
wrote:

> On 7 Mrz., 08:03, "Ulrich M. Schwarz" <brother...@gmx.net> wrote:

Well, yes and no. _Optional_ arguments always go in brackets, _mandatory_
arguments always go in curlies.
But you cannot have a mandatory argument with a default value, because the
default would never be used.
tabular needs the specification of the columns because there's no
reasonable default. If you omit the default specification [0pt] in your
definition, #1 will turn into a mandatory argument and you'll have to put
it in curlies.

HTH
Ulrich

0 new messages