[texhax] very long nested expressions in math-mode

Torsten Anders torstenanders at gmx.de
Wed Oct 19 07:50:54 CEST 2005


Dear Douglas Lewan,

Thank you very much for your reply and the pointer to the interesting 
article. Looking at the source of the article, however, I had to 
realise that even L. Lamport did not introduce some some 'magic' which 
would allow me to define more nice and clean Latex commands (as my 
'dream \Apply' discussed in the previous email).

It may be the I am aiming for something which is incompatible with the 
way Latex/Tex layouts a page by nesting boxes: I would like to write a 
Latex command which in some way changes the height of the current line 
for the text after the command.

Is there a way to define a command \MyBox{} whose top would align with 
the current line and the the text after the box would continue at the 
bottom of the box, even if \MyBox{} spans over multiple lines? For 
example, the following line of Latex code would result in the layout 
below:

Some Text \MyBox{A A A\\A A A\\A A A} text continued

Some Text A A A
                   A A A
                   A A A text continued


Of course, I can define something like

\DoLayout{Some Text}{A A A\\A A A\\A A A}{text continued}

but that would result in much more complex coding of the examples..

Thank you very much!

Best wishes,
Torsten

On 18.10.2005, at 20:35, Douglas Lewan wrote:
> You might want to consider this reference:
>
> http://research.microsoft.com/users/lamport/proofs/proofs.html
>
> --- Torsten Anders <torstenanders at gmx.de> wrote:
>> Dear all,
>>
>> Firstly, I should mention that I am new to this
>> list. I read the FAQ
>> and quite some docomentation to find an answer to my
>> problem, without
>> success unfortunately. Nevertheless, I apologise in
>> case I missed
>> something obvious.
>>
>> I want to transform program source examples into
>> mathematical notation
>> in Latex (tetex, i.e. incl. AMS packages), because
>> that way the
>> examples become more concise and better to
>> communicate. Because the
>> source is based on functional and logic programming,
>> the available
>> algorithm packages are less suited -- the result is
>> too easily misread
>> as procedural programming. Instead, I would prefer
>> to write plain math
>> expressions.
>>
>> In short, my problem is that I need to write rather
>> long expressions
>> (e.g. highly nested and with long variable names for
>>
>> comprehensibility). Thus, line breaks are
>> inevitable. Naturally, the
>> continued expression should be indented to indicate
>> the nested
>> structure of the expression. That is, I don't what
>> to mechanically
>> indent by a certain amount (e.g. by \quad), but the
>> indentation should
>> depend on the indentation depth of the surrounding,
>> e.g., function
>> call. For instance, a short dummy example may read
>> like this:
>>
>> xs = find(map([1, 2, 3],
>>                          f : f(x) = x^3),
>>                isEven)
>>
>> The most easy way to do something like this is
>> probably to use
>> mono-space fonts in some verbatim environment.
>> However, I would prefer
>> to write my example in Latex's math mode: e.g., I
>> would prefer to use
>> signs like \vee, \wedge, \bigwedge etc.
>>
>> To avoid getting lost in my own long Latex examples,
>> I would like to
>> define some suitable Latex command, e.g., to get the
>> example above I
>> would like to write something like
>>
>> $xs = \Apply{find}{\Apply{map}{[1,2,3], \\ f : f(x)
>> = x^3}, \\ isEven}$
>>
>> So far I did not find a way to define \Apply as
>> above and get a
>> suitable output. In the following, I present a few
>> of my attempts to
>> set my examples. However, none of what I came up
>> with so far is really
>> satisfying. Perhaps anybody here can help me..
>>
>> Here comes my first naive attempt to define \Apply:
>>
>> \newcommand{\Apply}[2]{\ensuremath{#1 (
>> \begin{aligned}[t] #2
>> \end{aligned} ) }}
>>
>> which is called
>>
>> $xs = \Apply{find}{&\Apply{map}{&[1,2,3], \\ &f :
>> f(x) = x^3}, \\
>> &isEven}$
>>
>> The additional '&' makes the code slightly less
>> readable, but the
>> actual problem is that everything after the aligned
>> environment (i.e.
>> the comma and the cloing parenthesis) 'go back' on
>> the original line
>> like
>>
>> xs = find(map([1, 2, 3],	 ),)
>>                          f : f(x) = x^3
>>                isEven
>>
>> Next try:
>>
>> \newcommand{\Apply}[3]{\ensuremath{#1 (
>> \begin{aligned}[t] #2 ) #3
>> \end{aligned} }}
>>
>> $xs = \Apply{find}{&\Apply{map}{&[1,2,3], \\ &f :
>> f(x) = x^3}{,} \\
>> &isEven}{}$
>>
>> This results in the desired output, but for complex
>> examples with
>> parenthesis/brackets/curly braces in the third
>> \Apply argument this
>> becomes very hard to read and the editor (i.e.
>> emacs) can't help
>> anymore.
>>
>> To avoid the problem that after a box -- which
>> starts at the current
>> line but introduces some line breaks -- the current
>> line is _not_
>> continued I tried to center the whole expression:
>>
>> \newcommand{\Apply}[2]{\ensuremath{#1 \left(
>> \begin{aligned} #2
>> \end{aligned} \right) }}
>>
>> $xs = \Apply{find}{&\Apply{map}{&[1,2,3], \\ &f :
>> f(x) = x^3}, \\
>> &isEven}$
>>
>> The structure of the resulting expression is still
>> clearly readable and
>> the code is also more easy to write. However, this
>> layout can also
>> easily be misread: instead surrounding the arguments
>> of a function call
>> the parenthesis look more like a binom (and reducing
>> the gap between
>> the function name and the parenthesis does not
>> really overcome that).
>> :-P
>>
>> Does anybody have a better idea how to set very long
>> nested
>> expressions? Any help is most appreciated!
>>
>> Best wishes,
>> Torsten
>>
>> --
>> Torsten Anders
>> Sonic Arts Research Centre
>> Queen's University Belfast (UK)
>> www.torsten-anders.de
>>
>> _______________________________________________
>> TeX FAQ: http://www.tex.ac.uk/faq
>> TeX newsgroup:
>> http://groups.google.com/groups?group=comp.text.tex
>> Mailing list archives:
>> http://tug.org/pipermail/texhax/
>> More links: http://tug.org/begin.html
>>
>> Automated subscription management:
>> http://tug.org/mailman/listinfo/texhax
>> Human mailing list managers: postmaster at tug.org
>>
>
> _______________________________________________
> TeX FAQ: http://www.tex.ac.uk/faq
> TeX newsgroup: http://groups.google.com/groups?group=comp.text.tex
> Mailing list archives: http://tug.org/pipermail/texhax/
> More links: http://tug.org/begin.html
>
> Automated subscription management: 
> http://tug.org/mailman/listinfo/texhax
> Human mailing list managers: postmaster at tug.org
>
--
Torsten Anders
Sonic Arts Research Centre
Queen's University Belfast (UK)
www.torsten-anders.de



More information about the texhax mailing list