Article View: comp.text.tex
Article #10667Re: how to define a LaTeX environment with an *optional* argument?
From: Donald Arseneau
Date: Fri, 22 Jan 1993 23:30
Date: Fri, 22 Jan 1993 23:30
31 lines
1708 bytes
1708 bytes
In article <1jpnnsINN5el@retriever.cs.umbc.edu>, finin@cs.umbc.edu (Timothy Finin) writes...
>Is there a way to define an environment in LaTeX that takes a single
>optional argument?
>I would like to have the argument to boxed be optional and default to,
>say \defaultBoxWidth. Is there a way to do this within LaTeX, or does
>one have to define this directly in TeX?
>
Yes and no. All of LaTeX is implemented "directly in TeX", but you can
look at how LaTeX does it to do the same thing yourself. Look in the
LaTeX.tex file.
\newsavebox{\mybox}
> \newenvironment{boxed}[1]%
> {\beginsbox{\mybox}\begin{minipage}{#1}%
> }%
> {\end{minipage}\endsbox
> \setlength{\fboxsep}{8pt}%
> \centerline{\fbox{\usebox{\mybox}}}}
>
becomes:
% in a style file or use \makeatletter
\def\boxed{\@ifnextchar[{\@box@d}{\@box@d[\defaultBoxWidth]}}
\def\@box@d[#1]{\beginsbox{\mybox}\begin{minipage}{#1}}
\def\endboxed{\end{minipage}\endsbox
\setlength{\fboxsep}{8pt}%
\centerline{\fbox{\usebox{\mybox}}}
Donald Arseneau asnd@reg.triumf.ca
Technical Details
Message-ID:
<22JAN199315302220@reg.triumf.ca>Path:
arc1-ca.pugleaf.net!sparky!uunet!paladin.american.edu!howland.reston.ans.net!usc!sdd.hp.com!caen!batcomputer!cornell!uw-beaver!cs.ubc.ca!unixg.ubc.ca!reg.triumf.ca!asndReferences:
<1jpnnsINN5el@retriever.cs.umbc.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!paladin.american.edu!howland.reston.ans.net!usc!sdd.hp.com!caen!batcomputer!cornell!uw-beaver!cs.ubc.ca!unixg.ubc.ca!reg.triumf.ca!asnd From: asnd@reg.triumf.ca (Donald Arseneau) Newsgroups: comp.text.tex Subject: Re: how to define a LaTeX environment with an *optional* argument? Date: 22 Jan 1993 15:30 PST Organization: TRIUMF: Tri-University Meson Facility Lines: 31 Distribution: world Message-ID: <22JAN199315302220@reg.triumf.ca> References: <1jpnnsINN5el@retriever.cs.umbc.edu> NNTP-Posting-Host: reg.triumf.ca News-Software: VAX/VMS VNEWS 1.41