LATEX-L Archives

Mailing list for the LaTeX3 project

LATEX-L@LISTSERV.UNI-HEIDELBERG.DE

Options: Use Forum View

Use Monospaced Font
Show Text Part by Default
Condense Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Sender:
Mailing list for the LaTeX3 project <[log in to unmask]>
Date:
Mon, 16 Jan 2017 23:23:43 +1300
MIME-version:
1.0
Reply-To:
Mailing list for the LaTeX3 project <[log in to unmask]>
Content-type:
text/plain; charset=utf-8; format=flowed
Subject:
From:
Andrew Parsloe <[log in to unmask]>
In-Reply-To:
Message-ID:
Content-transfer-encoding:
7bit
Parts/Attachments:
text/plain (73 lines)
On 16/01/2017 9:36 p.m., Joseph Wright wrote:
> On 16/01/2017 08:19, David Carlisle wrote:
>> On 16/01/2017 00:58, Andrew Parsloe wrote:
>>> Only recently have I learnt to distinguish inline from display-style
>>> maths mode by using \mode_if_inner:TF. It would be helpful for those of
>>> us who come to expl3 programming without a good prior grounding in TeX
>>> if a comment to this effect could be added to the documentation
>>> (interface3.pdf).
>>>
>>> Andrew
>>
>> \mode_if_inner:TF is a wrapper around \ifinner so can't be used to
>> distinguish inline from display. In fact in math \ifinner can't be used
>> to detect much useful at all, the points at which tex is or is not in
>> inner math mode are not usually interesting. (Unlike testing for inner
>> when in vertical mode that tells you if you are in a box or on the main
>> vertical list)
>
> Indeed, one cannot be sure that display math mode will actually be used
> for any 'display' anyway. See for example the strategy used by breqn:
> all typesetting is done in inline math mode, using \displaystyle where
> appropriate. (Display math mode is used only for obtaining the length of
> the line of text immediately preceding the 'display'.)
>
> Almost certainly you want to use \mathchoice (currently there is no
> interface for this in expl3 beyond the primitive), though you might also
> look at LuaTeX's additional primitives in this area if you are
> considering a 'LuaTeX-only' solution.
>
> Joseph
>
I had forgotten \mathchoice.

I'm not qualified to argue about the use of \mode_if_inner:TF beyond 
saying that it has correctly worked to date. *All* the cases of interest 
to me are of the following kind. #1 is a token list digestible by 
\fp_eval:n (usually with more * and parentheses than are strictly 
needed); #2 is a token list consisting of digits and a decimal point (in 
fact the rounded decimal number resulting from the fp evaluation of #1).

Andrew

\documentclass{article}
\usepackage{expl3,xparse,amsmath}
\begin{document}
\ExplSyntaxOn

\DeclareDocumentCommand \testinner { m m }
   {
     \mode_if_inner:TF
       { \mbox{#1} \to\quad { #2 } }
       {
	\begin{aligned}
	\mbox{#1} & \to \\
	  & { #2 }  \\
	\end{aligned}
       }
   }

\ExplSyntaxOff

This is an inline $ \testinner { 2*sin(pi/12)*cos(pi/12) } 
{2\sin(\pi/12)\cos(\pi/12)=0.5 } $ expression.

This is a \[ \testinner { 2*sin(pi/12)*cos(pi/12) } { 
2\sin(\pi/12)\cos(\pi/12)=0.5 } \]display-style expression.

\end{document}

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

ATOM RSS1 RSS2