ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Nath, and problems smashing
@ 2003-04-11 20:42 Giuseppe Bilotta
  2003-04-12 20:37 ` Simon Pepping
  0 siblings, 1 reply; 3+ messages in thread
From: Giuseppe Bilotta @ 2003-04-11 20:42 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 940 bytes --]

Hello,

as I might have mentioned before, I'm working on a ConTeXt module
that would give part of the functionality available in the LaTeX
package Nath; as I'm not really an expert in either of the topics
involved, I'm going at it slowly, starting with the simple things;
the first thing I implemented was a natural way to write
extensible arrows. It came up pretty fine and works quite good,
but there seems to be a sizing problem.

First of all, please find attached t-nath.tex (the module) and
nathtest.tex (a test file).

As you may notice if you compile the nathtest document, sub and
superscripts to the single-line arrows are much to high or low;
browsing about I noticed that in AMS-LaTeX the minus that extends
the single-line arrows is "smashed", to prevent this problem; I
did try to smash it (replacing \mathop- with \mathop{\smash-}),
but it didn't seem to help.

What do the experts here think?

-- 
Giuseppe "Oblomov" Bilotta

[-- Attachment #2: nathtest.tex --]
[-- Type: application/octet-stream, Size: 593 bytes --]

\let\[\startformula
\def\]{\stopformula\ignorespaces}

\usemodule[nath]

\starttext

This thingie is supposed to test the Nath package.

\section{Extensible arrows}

With nothing:
\[
A \to B \iff C \implies D \follows E
\]

With superscript:
\[
A \to^{a^b} B \iff^{a_b} C \implies^{a^b} D \follows^{a_b} E
\]

With subscript:
\[
A \to_{a_b} B \iff_{a^b} C \implies_{a_b} D \follows_{a^b} E
\]

With subersup:
\[
A \to_a^b B \iff_a^b C \implies_a^b D \follows_a^b E
\]

With supersub:
\[
A \to^a_b B \iff^a_b C \implies^a_b D \follows^a_b E
\]

\stoptext


[-- Attachment #3: t-nath.tex --]
[-- Type: application/octet-stream, Size: 5169 bytes --]

%D \module
%D   [      file=t-nath,
%D        version=2003.04.11,
%D          title=\CONTEXT\ User Module, 
%D       subtitle=Natural mATH,
%D         author=Giuseppe Bilotta,
%D           date=\currentdate,
%D      copyright={PRAGMA / Giuseppe Bilotta}]

%D This ConTeXt module is intended to provide Nath-like
%D functionality to ConTeXt

\unprotect

%D The following is used when we want to scan for sub- or
%D superscripts to a command.

\newtoks\supertoks
\newtoks\subertoks

\newif\ifsuper
\newif\ifsuber

\def\subsup!parse{
  \superfalse\suberfalse
  \def\next!command{\afterassignment\subsup!!parse\let\next=}%
  \next!command
}

\def\subsup!!parse{%
  \ifx\next_
    \ifsuber
      % TODO report error for double subscript
    \else\subertrue
    \fi
    \def\next!command{\sb!!}
  \else
    \ifx\next^
      \ifsuper
        % TODO report error for double superscript
      \else\supertrue
      \fi
      \def\next!command{\sp!!}
    \else
      \def\next!command{\aftersubsupparse}
    \fi
  \fi
  \next!command
}

\def\sp!!#1{\supertoks{#1}\afterassignment\subsup!!parse\let\next=}
\def\sb!!#1{\subertoks{#1}\afterassignment\subsup!!parse\let\next=}

\let\aftersubsupparse\relax

%D We use it instantly for our first thing:
%D extensible arrows

\def\arrowfiller{%
 \cleaders\hbox{\mathematics{\mkern-3mu\mathord-\mkern-3mu}}%
}

\def\doublearrowfiller{%
 \cleaders\hbox{\mathematics{\mkern-3mu\mathord=\mkern-3mu}}%
}

\def\doarrowfill#1#2{%
  \setbox\!!boxa\hbox{\mathematics{\scriptscriptstyle#1}}%
  \setbox\!!boxb\hbox{\mathematics{\scriptscriptstyle#2}}%
  \ifdim\wd\!!boxa>\wd\!!boxb
    \scratchdimen\wd\!!boxa
  \else
    \scratchdimen\wd\!!boxb
  \fi
  \hbox to \scratchdimen{\arrowfiller\hfill}%
}

\def\dodoublearrowfill#1#2{%
  \setbox\!!boxa\hbox{\mathematics{\scriptscriptstyle#1}}%
  \setbox\!!boxb\hbox{\mathematics{\scriptscriptstyle#2}}%
  \ifdim\wd\!!boxa>\wd\!!boxb
    \scratchdimen\wd\!!boxa
  \else
    \scratchdimen\wd\!!boxb
  \fi
  \hbox to \scratchdimen{\doublearrowfiller\hfill}%
}

\def\xarrow#1#2#3#4#5{% sup sub left right default
  \doifelse{#1#2}\empty{#5}{%
    % \message{Doing something with: .#1#2.^^J}%
    \mathrel{%
      \mathop{%
        \mathopen{#3}\mkern-6mu
        \doarrowfill{#1}{#2}
        \mkern-6mu\mathclose{#4}
      }\limits^{\hss\scriptscriptstyle#1\hss}_{\hss\scriptscriptstyle#2\hss}%
    }
  }%
}

% \def\xrightarrow#1#2{%
%   \doifelse{#1#2}\empty\rightarrow{%
%     % \message{Doing something with: .#1#2.^^J}%
%     \mathrel{%
%       \mathop{%
%         \mathopen-\mkern-6mu
%         \doarrowfill{#1}{#2}
%         \mkern-6mu\mathclose\rightarrow
%       }\limits^{\hss\scriptscriptstyle#1\hss}_{\hss\scriptscriptstyle#2\hss}%
%     }
%   }%
% }

\def\xrightarrow#1#2{\xarrow{#1}{#2}-\rightarrow\rightarrow}
\def\xleftarrow#1#2{\xarrow{#1}{#2}\leftarrow-\leftarrow}
\def\xleftrightarrow#1#2{\xarrow{#1}{#2}\leftarrow\rightarrow\leftrightarrow}
\def\xmapsto#1#2{\xarrow{#1}{#2}\mapstochar\rightarrow{\mapstochar\rightarrow}}

\def\xdoublearrow#1#2#3#4#5{% sup sub left right default
  \doifelse{#1#2}\empty{#5}{%
    % \message{Doing something with: .#1#2.^^J}%
    \mathrel{%
      \mathop{%
        \mathopen{#3}\mkern-6mu
        \dodoublearrowfill{#1}{#2}
        \mkern-6mu\mathclose{#4}
      }\limits^{\hss\scriptscriptstyle#1\hss}_{\hss\scriptscriptstyle#2\hss}%
    }%
  }%
}

\def\xRightarrow#1#2{\xdoublearrow{#1}{#2}=\Rightarrow\Rightarrow}
\def\xLeftarrow#1#2{\xdoublearrow{#1}{#2}\Leftarrow=\Leftarrow}
\def\xLeftrightarrow#1#2{\xdoublearrow{#1}{#2}\Leftarrow\Rightarrow\Leftrightarrow}
\def\xLongleftrightarrow#1#2{\xdoublearrow{#1}{#2}\Leftarrow\Rightarrow\Longleftrightarrow}

\unexpanded\def\to{%
  \def\aftersubsupparse{%
    \xrightarrow{\ifsuper\the\supertoks\fi}{\ifsuber\the\subertoks\fi}%
    \next}%
%   \suberfalse\superfalse\def\next!command{\afterassignment\subsup!!parse\let\next=}%
%   \next!command
    \subsup!parse
}

\unexpanded\def\ot{%
  \def\aftersubsupparse{%
    \xleftarrow{\ifsuper\the\supertoks\fi}{\ifsuber\the\subertoks\fi}%
    \next}%
    \subsup!parse
}

\unexpanded\def\otto{%
  \def\aftersubsupparse{%
    \xleftrightarrow{\ifsuper\the\supertoks\fi}{\ifsuber\the\subertoks\fi}%
    \next}%
    \subsup!parse
}

\unexpanded\def\mapsto{%
  \def\aftersubsupparse{%
    \xmapsto{\ifsuper\the\supertoks\fi}{\ifsuber\the\subertoks\fi}%
    \next}%
    \subsup!parse
}

\unexpanded\def\implies{%
  \def\aftersubsupparse{%
    \xRightarrow{\ifsuper\the\supertoks\fi}{\ifsuber\the\subertoks\fi}%
    \next}%
%   \suberfalse\superfalse\def\next!command{\afterassignment\subsup!!parse\let\next=}%
%   \next!command
    \subsup!parse
}

\unexpanded\def\follows{%
  \def\aftersubsupparse{%
    \xLeftarrow{\ifsuper\the\supertoks\fi}{\ifsuber\the\subertoks\fi}%
    \next}%
    \subsup!parse
}

\unexpanded\def\iff{%
  \def\aftersubsupparse{%
    \xLongleftrightarrow{\ifsuper\the\supertoks\fi}{\ifsuber\the\subertoks\fi}%
    \next}%
    \subsup!parse
}

\protect

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Nath, and problems smashing
  2003-04-11 20:42 Nath, and problems smashing Giuseppe Bilotta
@ 2003-04-12 20:37 ` Simon Pepping
  2003-04-13 12:03   ` Re[2]: " Giuseppe Bilotta
  0 siblings, 1 reply; 3+ messages in thread
From: Simon Pepping @ 2003-04-12 20:37 UTC (permalink / raw)


Hi,
On Fri, Apr 11, 2003 at 10:42:28PM +0200, Giuseppe Bilotta wrote:
> Hello,
> 
> as I might have mentioned before, I'm working on a ConTeXt module
> that would give part of the functionality available in the LaTeX
> package Nath; as I'm not really an expert in either of the topics
> involved, I'm going at it slowly, starting with the simple things;
> the first thing I implemented was a natural way to write
> extensible arrows. It came up pretty fine and works quite good,
> but there seems to be a sizing problem.

A good idea.
 
> As you may notice if you compile the nathtest document, sub and
> superscripts to the single-line arrows are much to high or low;
> browsing about I noticed that in AMS-LaTeX the minus that extends
> the single-line arrows is "smashed", to prevent this problem; I
> did try to smash it (replacing \mathop- with \mathop{\smash-}),
> but it didn't seem to help.

You require two smashes to get the height and depth equal to that of
rightarrow.

\usemodule[nath]

\starttext

Arrowfiller: 
\setbox0\hbox to 6pt{\arrowfiller \hfill }
height: \the\ht0,
depth: \the\dp0.

Smash in arrowfiller: 
\def\arrowfiller {\cleaders \hbox {\mathematics {\mkern -3mu\mathord
{\smash -}\mkern -3mu}}}
\setbox0\hbox to 6pt{\arrowfiller \hfill }
height: \the\ht0,
depth: \the\dp0.

Another smash in the opening minus:
\setbox0\hbox {$\mathop {\mathopen {\smash -}\mkern -6mu \doarrowfill
{\ifsuper \the \supertoks \fi }{\ifsuber \the \subertoks \fi } \mkern
-6mu\mathclose {\rightarrow }}$}
height: \the\ht0,
depth: \the\dp0.

Rightarrow:
\setbox0\hbox {$\rightarrow$}
height: \the\ht0,
depth: \the\dp0.

\stoptext

Regards, Simon

-- 
Simon Pepping
email: spepping@scaprea.hobby.nl

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re[2]: Nath, and problems smashing
  2003-04-12 20:37 ` Simon Pepping
@ 2003-04-13 12:03   ` Giuseppe Bilotta
  0 siblings, 0 replies; 3+ messages in thread
From: Giuseppe Bilotta @ 2003-04-13 12:03 UTC (permalink / raw)


Saturday, April 12, 2003 Simon Pepping wrote:

>> As you may notice if you compile the nathtest document, sub and
>> superscripts to the single-line arrows are much to high or low;
>> browsing about I noticed that in AMS-LaTeX the minus that extends
>> the single-line arrows is "smashed", to prevent this problem; I
>> did try to smash it (replacing \mathop- with \mathop{\smash-}),
>> but it didn't seem to help.

SP> You require two smashes to get the height and depth equal to that of
SP> rightarrow.

BINGO! Thanks.

-- 
Giuseppe "Oblomov" Bilotta

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-04-13 12:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-04-11 20:42 Nath, and problems smashing Giuseppe Bilotta
2003-04-12 20:37 ` Simon Pepping
2003-04-13 12:03   ` Re[2]: " Giuseppe Bilotta

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).