diff options
author | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
commit | e0c6872cf40896c7be36b11dcc744620f10adf1d (patch) | |
tree | 60335e10d2f4354b0674ec22d7b53f0f8abee672 /macros/latex/contrib/mhequ |
Initial commit
Diffstat (limited to 'macros/latex/contrib/mhequ')
-rw-r--r-- | macros/latex/contrib/mhequ/README | 19 | ||||
-rw-r--r-- | macros/latex/contrib/mhequ/example.pdf | bin | 0 -> 98452 bytes | |||
-rw-r--r-- | macros/latex/contrib/mhequ/example.tex | 94 | ||||
-rw-r--r-- | macros/latex/contrib/mhequ/mhequ.sty | 330 |
4 files changed, 443 insertions, 0 deletions
diff --git a/macros/latex/contrib/mhequ/README b/macros/latex/contrib/mhequ/README new file mode 100644 index 0000000000..66890d3eef --- /dev/null +++ b/macros/latex/contrib/mhequ/README @@ -0,0 +1,19 @@ +mhequ package by Martin Hairer +Version 1.7 dated 25/08/2015 + +This package provides an easy way to typeset multilign / multicolumn +equations and to add subequation numbering. See the example and the +comments at the beginning of mhequ.sty for usage instructions. + +Files included in the package: +====== Documentation ====== + +README +example.pdf +example.tex + +===== Files for LaTeX ===== + +mhequ.sty + +=========================== diff --git a/macros/latex/contrib/mhequ/example.pdf b/macros/latex/contrib/mhequ/example.pdf Binary files differnew file mode 100644 index 0000000000..d6813c2b83 --- /dev/null +++ b/macros/latex/contrib/mhequ/example.pdf diff --git a/macros/latex/contrib/mhequ/example.tex b/macros/latex/contrib/mhequ/example.tex new file mode 100644 index 0000000000..c0eca63f65 --- /dev/null +++ b/macros/latex/contrib/mhequ/example.tex @@ -0,0 +1,94 @@ +\documentclass{article} +\usepackage{mhequ} + +\def\eref#1{(\ref{#1})} + +\textwidth 13cm +\textheight 22cm +\oddsidemargin 0.2cm +\topmargin 0.3cm +\pagestyle{empty} + +\begin{document} + +\title{Using the mhequ package} +\author{Martin Hairer} +\date{Version 1.7, \today} +\maketitle +\thispagestyle{empty} + +\label{mySec} +Here is a simple labelled equation: +\begin{equ}[onelab] + \sum_{i=1}^5 X_i^j X^j_i = y^j \;. +\end{equ} +Removing or adding the label does not require a change of environment: +\begin{equ} + \sum_{i=1}^5 X_i^j X^j_i = y^j \;. +\end{equ} +However, if the option \texttt{numberall} is set, then every single +equation is numbered. +A simple list of equations can be displayed either with one number +per equation +\begin{equs} + f(x) &= \sin(x) + 1\;, \label{e:equ1}\\ + h(x) &= f(x) + g(x) -3\;, \label{e:equ3} +\end{equs} +or with one number for the whole list +\begin{equs}[e:block] + f(x) &= \sin(x) + 1\;, \\ + h(x) &= f(x) + g(x) -3\;, +\end{equs} +using only a very small modification in the syntax. Of course, it can also have no number at all: +\begin{equs} + f(x) &= \sin(x) + 1\;, \\ + h(x) &= f(x) + g(x) -3\;. +\end{equs} +Let us make a first group: +\minilab{otherlabel} +\begin{equs} + f(x) &= \sin(x) + 1\;, \label{e:f}\\ + g(x) &= \cos(x) - x^2 + 4\;,\label{e:g}\\[3mm] + h(x) &= f(x) + g(x) -3\;. \label{e:h} +\end{equs} +One can refer to the whole block \eref{otherlabel} or to one +line, like \eref{e:f} for example. +It is possible to use any tag one likes with the \texttt{\string\tag} +command +\begin{equ}[mylabel] + x = y\;. \tag{$\star$} +\end{equ} +Such an equation can be referred to as usual: \eref{mylabel}. +Of course, \texttt{mhequ} can be used in conjunction with the usual \texttt{equation} environment, +but \texttt{mhequ} is great, so why would you want to do this? +\begin{equation} + x=y+z +\end{equation} +Typesetting several columns of equations is quite easy and doesn't require 10 different environments +with awkward names: +\begin{equs} + x&=y+z &\qquad a&= b+c &\qquad x&= v \label{laba}\\ + x&=y+z &\qquad a&= b+c &\qquad x&= u+1\tag{\ref{laba}'}\label{labtag}\\ + \multicol{4}{\text{(multicol)}} &\qquad x&=y \\ + a&= b &\multicol{4}{\qquad\text{(multicol)}} \\ + x&=y+z &\qquad a^2&= (b-c)^3 +y \\ +\intertext{and also (this is some \texttt{\string\intertext})} + x&=y+z &\qquad a&= (b+c)^2 - 5 &\qquad \ell&= m\label{labb} +\end{equs} +We can even extend the block \eref{otherlabel} much later like +\minilab{otherlabel} +\begin{equs} + x&=y+z &\quad x&=y+z &\quad f(x)&= b\label{e:x1}\\ + x&=y+z & x&=y+z &\quad g(x)&= b\label{e:x2} \\ + \multicol{6}{\sin^2 x + \cos^2 x = 1} \label{e:x3} +\end{equs} +It is possible to change the type of subnumbering and to use the +\texttt{\string\text} command without having to load \texttt{amstext}, like so +\setlabtype{Alph} +\minilab{alab} +\begin{equs} + I_1 &= \int_a^b g(x)\,dx\;,&\quad&\text{(First equation)} \label{e:1}\\ + I_2 &= \int_a^b g(x^2-1)\,dx\;.&\quad&\text{(Second equation)} \label{e:2} +\end{equs} + +\end{document}
\ No newline at end of file diff --git a/macros/latex/contrib/mhequ/mhequ.sty b/macros/latex/contrib/mhequ/mhequ.sty new file mode 100644 index 0000000000..f1708e4bfc --- /dev/null +++ b/macros/latex/contrib/mhequ/mhequ.sty @@ -0,0 +1,330 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% mhequ.sty v1.7, Copyright 2015 by Martin Hairer +% This package is public domain. You are strongly encouraged to use +% it and to distribute it further. If you have some contribution to +% it, please let me know! +% +% You may download the latest version of this package from +% +% http://www.hairer.org/software/mhequ.zip +% +% Notes: +% mhequ supports the packages "showkeys" (thus the [draft] option is suppressed) +% and "hyperref". +% +% Options: +% +% [lefttag] : Puts equation numbers to the left side of the page +% [righttag]: Puts equation numbers to the right side of the page (default) +% [numberall]: Numbers all equations +% +% Syntax: +% +% \begin{equ}[label] +% +% label : if a label is given, the equation is numbered. (default : no label) +% +% \begin{equs}[n][label] +% +% Creates a multiline / multicolumn equation environment. +% +% n : number of columns. (default : 5) You can also choose n=0. +% label : if a label is given, the environment is numbered. (one tag for the whole block) +% The order of [n] and [label] is irrelevant. +% +% If no label is given, one can number each line of the block individually by +% using the \label command. +% +% In the equs environment, the number of '&' signs per line has to be equal to +% 2*n-1 if n>0 and to 0 if n=0. If there are less '&' signs, they are automatically +% appended at the end of the line. +% +% Provided commands: +% +% \tag{theTag} Replaces the number of the current equation by "theTag" +% +% \notag Forces to have no tag (only useful if [numberall] is active) +% +% \minilab{label} If "label" has already been used, switches to the minilab "label". +% If not, creates a new minilab. Inside a minilab, equations are labelled +% (1a), (1b),... instead of (1), (2), etc... You can refer to the number +% of the minilab with \ref. +% +% \setlabtype{style} Sets the style of the numbering of the minilab. Default is +% \setlabtype{alph}. +% +% \intertext{material} Inserts 'material' between two lines in normal text mode. +% +% \multicol{n}{material} Spans n columns of the equation array with 'material'. It +% has to be placed between two & signs, or at the end or the start +% of the line. +% +% \text{material} Creates a \hbox containing 'material'. +% +% Warnings: +% +% If you use the \tag command, a quite large number of runs may be needed in +% order to get the desired output. +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\NeedsTeXFormat{LaTeX2e} +\ProvidesPackage{mhequ} +\DeclareOption{righttag}{\global\@MHleftfalse} +\DeclareOption{lefttag}{\global\@MHlefttrue} +\DeclareOption{numberall}{\global\@MHnumberalltrue} +\DeclareOption{fleqn}{\global\@MHflushtrue} +\DeclareOption{leqno}{\global\@MHlefttrue} + +\newif\if@MHhaslab +\newif\if@MHuseminilab +\newif\if@MHnumberall +\newcount\@MHnocols +\newcount\@MHnocolstot +\newif\if@MHtag +\newif\if@MHleft +\newif\if@MHflush +\@MHnumberallfalse + + +\ProcessOptions + +\def\MH@changecodes{\catcode`\:=12\catcode`\,=12\catcode`\.=12% + \catcode`\'=12\catcode`\*=12\catcode`\&=12} + +\def\@MHputleft#1{\hb@xt@.01\p@{}\rlap{\hskip-\displaywidth#1\@MHputnumber}} +\def\@MHputright#1{\hb@xt@.01\p@{}\llap{#1\@MHputnumber}} + +\if@MHleft\let\@MHput@lbl\@MHputleft% + \else\let\@MHput@lbl\@MHputright\fi + +\def\@MHresetlab{\if@MHnumberall\global\@MHhaslabtrue\else\global\@MHhaslabfalse\fi} +\@MHresetlab + +\def\@MHref#1{\@ifundefined{r@#1}{??}{\@saveref{#1}}} +%%%%% Computes the length of its argument +\newcount\@MHLength +\def\computelength#1{\@MHLength=0 \getlength#1\end} +\def\getlength#1{\ifx#1\end \let\next=\relax \else \advance\@MHLength by1 \let\next=\getlength \fi \next} + +\def\@makelabel#1{\refstepcounter{equation}\global\def\@mylabel{#1}% + \@ifundefined{c@lab@#1}{\newcounter{lab@#1}}{}\setcounter{lab@#1}{0}% + \immediate\write\@auxout{\string\@ifundefined{c@lab@#1}{\string\newcounter{lab@#1}}% + {}\string\setcounter{lab@#1}{0}}% + \global\expandafter\let\expandafter\c@MHCurrentCount\csname c@lab@#1\endcsname% + \global\@namedef{MHused@#1}{}% + \def\@currentlabel{\theequation}\MHsavelabel{#1}% + } +\def\@uselabel#1{\global\def\@mylabel{#1} + \global\expandafter\let\expandafter\c@MHCurrentCount\csname c@lab@#1\endcsname + } +\def\@MHreset{\global\def\@MHeqno{\theequation}\global\@MHuseminilabfalse\@MHresetlab} +\def\@MHbuildlab#1{\@ifundefined{r@#1}% + {\global\def\@MHeqno{\theequation\sublabeltype{MHCurrentCount}}}% + {\global\def\@MHeqno{\ref{\@mylabel}\sublabeltype{MHCurrentCount}}}% + } +\def\@MHUseLab#1{\@MHbuildlab{#1}\global\@MHuseminilabtrue} + + +\newskip\MHcenter \MHcenter=0pt plus 1000pt minus 1000pt +\newskip\MHbig \MHbig=1000pt plus 0pt minus 1000pt +\newskip\@MHlineskip +\def\openup{\afterassignment\@penup\dimen@=} +\def\@penup{\advance\lineskip\dimen@ + \advance\baselineskip\dimen@ + \advance\lineskiplimit\dimen@} +\newif\ifdt@p +\def\displ@y{\global\dt@ptrue\openup\jot\m@th + \everycr{\noalign{\ifdt@p \global\dt@pfalse \ifdim\prevdepth>-1000\p@ + \vskip-\lineskiplimit \vskip\normallineskiplimit \fi + \else \vskip\@MHlineskip\penalty\interdisplaylinepenalty \fi}}} +\def\@lign{\tabskip\z@skip\everycr{}}%% restore inside \displ@y +\def\displaylines#1{\displ@y \tabskip\z@skip + \halign{\hbox to\displaywidth{$\@lign\hfil\displaystyle##\hfil$}\crcr + #1\crcr}} + +\def\@MHcrl{{\ifnum0=`}\fi\@ifnextchar[{\@MHcrlwith}{\@MHcrlwith[\z@]}} +\def\@MHcrlwith[#1]{\ifnum0=`{\fi}\MH@dd@nds&\global\@MHlineskip=#1\cr} + +\def\@MHcrb{{\ifnum0=`}\fi\@ifnextchar[{\@MHcrbwith}{\@MHcrbwith[\z@]}} +\def\@MHcrbwith[#1]{\ifnum0=`{\fi}\MH@dd@nds\global\@MHlineskip=#1\cr} + +\def\@MHlabel#1{\global\@MHhaslabtrue\global\def\@MHcurrentlabel{#1}} + +\def\@MHwritelabel{\def\@currentlabel{\@MHeqno}% + \if@MHleft\kern\displaywidth\kern0.2truecm\else\kern0.2cm\fi% + \MHsavelabel{\@MHcurrentlabel}% + \if@MHleft\kern-\displaywidth\kern-0.2truecm\else\kern-0.2cm\fi} + +\def\@MHstep{\if@MHtag\else\if@MHuseminilab\stepcounter{MHCurrentCount}% + \else\refstepcounter{equation}\fi\fi} + +\def\@MHputnumber{\if@MHhaslab\@MHstep\if@MHleft\@MHwritelabel\fi% + \hbox{\rm(\@MHeqno)}% + \if@MHleft\else\@MHwritelabel\fi% + \fi\@MHresetlab} + +\def\@MHnotag{\@MHhaslabfalse} + +\def\@saveMHComms{\@restoretag\let\MHsavecr=\\\let\\=\@MHcr\let\@saveref=\ref\let\ref=\@MHref% + \let\MHsavelabel=\label\let\label=\@MHlabel\let\@MHsavemult\multicol\let\@MHsavetag\notag\let\notag\@MHnotag% + \let\multicol\@MHspan\let\@MHsavetext\text\let\text\hbox\let\@MHsaveequation\theequation\let\theequation\@MHequation} +\def\@restoreMHComms{\let\\=\MHsavecr\let\label=\MHsavelabel\@MHreset\let\ref=\@saveref% + \let\multicol\@MHsavemult\let\notag\@MHsavetag\let\text\@MHsavetext\let\theequation\@MHsaveequation\global\def\@MHequation{\@MHsaveequation}} + + + +\def\@minilab#1{\let\MHsavelabel=\label% + \@MHUseLab{#1}\@ifundefined{MHused@#1}% + {\@makelabel{#1}}{\@uselabel{#1}}% + \let\label=\MHsavelabel\egroup\global\@ignoretrue} +\def\minilab{\bgroup\MH@changecodes\@minilab} +\def\@MHequation{\@MHsaveequation} + + + +%% Preamble commands +\def\MHpre@ne{\MHs@tr@m\hfil$\MH@lign\displaystyle{\MHsh@rp}$\tabskip\z@skip&% + \MHdecrt@t$\MH@lign\displaystyle{{}\MHsh@rp}$} +\def\MHpretw@{\tabskip\z@skip&\hfil\MHdecrt@t$\MH@lign\displaystyle{\MHsh@rp}$% + \tabskip\z@skip&\MHdecrt@t$\MH@lign\displaystyle{{}\MHsh@rp}$} +\def\MHprethr@@{\hfil\tabskip\MHcenter&\tabskip\z@skip\my@MHput{\MHsh@rp}\crcr} +\def\MHprethr@@notag{\hfil\tabskip\MHcenter\crcr} +\def\MHd@cr{\global\advance\MHrem@inc@ls by -1} + +\def\@MHspan#1#2{\multispan{#1}\ifnum\MHrem@inc@ls<1\global\MHrem@inc@ls=\MHt@tc@ls + \global\advance\MHrem@inc@ls by 1\fi% + \global\advance\MHrem@inc@ls by -#1% + {\hfill$\displaystyle{#2}$\hfill}} + +%% Building the preamble +\newcount\MHC@ls +\newcount\MHt@tc@ls +\newcount\MHrem@inc@ls +\def\MH@ddonecol{\xdef\MHpre@mble{\MHpre@mble\MHpretw@}} +\def\MH@ddcols{\if\the\MHC@ls1\let\comm\relax\else% + \global\advance\MHt@tc@ls by 2% + \MH@ddonecol\advance\MHC@ls by -1% + \let\comm\MH@ddcols\fi\comm} +\def\MHm@kepre@mble#1{ + \if#10 + \global\MHt@tc@ls=0 + \xdef\MHpre@mble{\MHs@tr@m\hfil$\MH@lign\displaystyle{\MHsh@rp}$\MHpre@nd} + \else + \MHC@ls=#1 + \global\MHt@tc@ls=1 + \xdef\MHpre@mble{\MHpre@mble\MHpre@ne} + \MH@ddcols + \xdef\MHpre@mble{\MHpre@mble\MHpre@nd} + \fi + } + +%% Build enough & signs to fill up the box +\def\MHm@ke@nds{\if\the\MHrem@inc@ls0\let\comm\relax\else% + \xdef\MH@nds{\MH@nds &}\global\advance\MHrem@inc@ls by -1% + \let\comm\MHm@ke@nds% + \fi\comm} +\def\MH@dd@nds{\def\MH@nds{}\MHm@ke@nds\MH@nds} +\def\MHr@mto@ne{\global\MHrem@inc@ls=\MHt@tc@ls} + +\def\MH@initone{\gdef\MHpre@mble{} + \let\MH@restoretag\relax\let\MHsh@rp\relax\let\MH@lign\relax + \let\my@MHput\relax\let\MHdecrt@t\relax\let\MHs@tr@m\relax%\let\@MHfill\relax + } +\def\MH@inittwo{\let\MH@restoretag\@restoretag\let\MHsh@rp##\let\MH@lign\@lign + \let\my@MHput\@MHput@lbl\let\MHdecrt@t\MHd@cr\let\MHs@tr@m\MHr@mto@ne%\let\@MHfill\my@fill + \MHpre@mble + } + +\def\@newalign#1{\displ@y\tabskip\MHcenter + \MH@initone + \let\MHpre@nd\MHprethr@@ + \MHm@kepre@mble{#1} + \xdef\MHpre@mble{\halign to\displaywidth\bgroup\MH@restoretag\MHpre@mble} + \MH@inittwo + } +\def\@newbalign#1{\vcenter\bgroup\displ@y\tabskip\MHcenter + \MH@initone + \let\MHpre@nd\MHprethr@@notag + \MHm@kepre@mble{#1} + \xdef\MHpre@mble{\halign to\displaywidth\bgroup\MHpre@mble} + \MH@inittwo + } + + +\def\@begalign[#1]{\global\let\@MHcr\@MHcrl$$\@saveMHComms\@newalign{#1}} + +\def\@ealign{\@MHcr\egroup} + +\def\@restoretag{\if@MHtag\global\@MHtagfalse\global\let\@MHeqno=\@MHsaveno\fi} +\def\@MHtag#1{% + \global\@MHtagtrue\global\let\@MHsaveno=\@MHeqno% + \global\def\@MHeqno{#1}\egroup} +\def\tag{\bgroup\MH@changecodes\@MHtag} + +\def\@equnolabel{\@MHresetlab} +\def\@equlabel[#1]{\label{#1}\global\@MHhaslabtrue} + +\def\@ealignb{\@MHcr\egroup\egroup} + +\def\@equbopt[#1]{\computelength{#1}\ifnum\@MHLength=1\@MHnocols=#1\else + \label{#1}\global\@MHhaslabtrue\fi + \@ifnextchar[{\@equbopt}{\@equb}} +\def\@equb{\@newbalign{\the\@MHnocols}} + +%\def\equa{\global\let\@MHcr\@MHcrb% +% $$\@saveMHComms\global\@MHnocols=1% +% \@ifnextchar[{\@equbopt}{\@equb}} +%\def\endequa{\@ealignb\if@MHhaslab\@MHput@lbl{}\fi% +% \@restoreMHComms$$\global\@ignoretrue} + +\if@MHflush + \def\equ{\@saveMHComms + \@beginparpenalty\predisplaypenalty + \@endparpenalty\postdisplaypenalty + \trivlist\item[]\leavevmode + \hb@xt@\linewidth\bgroup $\m@th% $ + \displaystyle + \hskip\mathindent\@ifnextchar[\@equlabel\@equnolabel} +\def\endequ{% + $\hfil % $ + \displaywidth\linewidth\hbox{\@MHputnumber}% + \egroup + \endtrivlist\@restoreMHComms\global\@ignoretrue} +\else + \def\equ{$$\@saveMHComms\@ifnextchar[\@equlabel\@equnolabel} + \def\endequ{% + \if@MHhaslab\if@MHleft\leqno\else\eqno\fi{\@MHputnumber}\fi% + \@restoreMHComms$$\global\@ignoretrue} +\fi + +%\def\equs{\@ifnextchar[{\@begalign}{\@begalign[1]}} +%\def\endequs{\@ealign\@restoreMHComms$$\global\@ignoretrue} + + +\newif\if@isequa +\def\@analyzearg[#1]{\computelength{#1}\ifnum\@MHLength=1\@MHnocols=#1\else + \@MHlabel{#1}\global\@isequatrue\fi% + \@ifnextchar[{\@analyzearg}{\if@isequa% + \global\let\@MHcr\@MHcrb% + $$\@saveMHComms\@equb% + \else\@begalign[\the\@MHnocols]\fi}} +\def\@endequs{\@ealign\@restoreMHComms$$} +\def\@endequa{\@ealignb\if@MHhaslab\@MHput@lbl{}\fi% + \@restoreMHComms$$} +\def\equs{\global\@isequafalse\@MHnocols=5\@ifnextchar[{\@analyzearg}{\@begalign[5]}} +\def\endequs{\if@isequa\@endequa\else\@endequs\fi\global\@ignoretrue} +\let\equa\equs +\let\endequa\endequs + +\def\setlabtype#1{\global\expandafter\let\expandafter\sublabeltype\csname #1\endcsname} + +\@MHreset +\let\sublabeltype=\alph +\def\intertext#1{\noalign{\noindent#1}} + +\def\strutdepth{0pt} +\def\@MHmargin#1{\strut\vadjust{\kern-\strutdepth\@MHspecial{#1}}} +\def\@MHspecial#1{\vtop to \strutdepth{\baselineskip\strutdepth\vss\llap{#1}\null}} + +\let\MHgobble\@gobblecr |