Debian Codegraph @

texmf-dist/doc/latex/asmeconf/examples/asmeconf-wide-equation-example/asmewide.sty

raw
1 %%
2 %% This file is `asmewide.sty'.
3 %%
4 %% Copyright (c) 2025 John H. Lienhard. Use under the MIT license: https://ctan.org/license/mit
5 %%
6 %% Defines a widetext environment within ASME dimensions
7 %% Use for material spanning both columns (i.e., for wide equations)
8 %%
9 %% The original widetext environment was developed in revtex; elements of the present code have been modified revtex4-2.dtx, under LPPL1.3c.
10 %% The unmodified code is available at: https://ctan.org/pkg/revtex
11 %% This code also adopts concepts from the widetext.sty package by Anjishnu Sarkar, https://blog.pnas.org/widetext.sty.
12 %% The modifications made were: follow ASME dimensions; remove revtex-specific macros; update/rework commands; adapt to most recent cuted.sty
13 %% (Leaders don't vanish at pagebreaks, as in revtex, evidently related to how cuted.sty handles strip construction. Have coded around this.)
14 %%
15 %% Required packages: cuted.sty v2.0 and flushend.sty v4.0 [2021/10/04] or later;
16 %% asmeconf.cls or asmejour.cls w/their required packages, esp. etoolbox, xparse
17 %%
18 %% The widetext environment can only appear once per page. It clashes with floats and footnotes,
19 %% and often requires some hand-fitting of page layouts.
20 %%
21 %% USAGE: \begin{widetext} ...wide material here... \end{widetext}
22 %% OPTIONAL ARGUMENTS:
23 %% \begin{widetext[N] ...change upper/lower separation of wide material from default Xpt to Npt (X = 5pt asmeconf.cls; X = 10pt asmejour.cls)
24 %% \begin{widetext}[][tbn]: t = top line only; b = bottom line only; n = no lines. BOTH arguments are REQUIRED, even if first is left empty.
25 %%
26 %% asmewide,sty supports one option, [raggedend], which suppresses final page column balancing: \usepackage[raggedend]{asmewide}
27 %%
28 %% NB: the strip environment from cuted is incompatible with the [lineno] option to asmeconf and asmejour!
29 %%
30 \NeedsTeXFormat{LaTeX2e}
31
32 \def\AW@versionno{1.11}
33 \def\AW@versiondate{2025/01/22\space}
34 \ProvidesPackage{asmewide}[\AW@versiondate\space v\AW@versionno\space ASME wide equation environment (JHL)]
35
36 \DeclareOption{raggedend}{% Added 2022/05/08, to suppressed flushend on last page, if desired
37 \AfterEndPreamble{\raggedend}
38 }
39 \DeclareOption*{}
40 \ProcessOptions \relax
41
42 \ifdefined\NewDocumentCommand\else
43 \RequirePackage{xparse}
44 \fi
45 \RequirePackage{etoolbox}
46 \RequirePackage{cuted}[2021/10/04]%features used here were first added in the [2021/10/04] version of cuted.sty!
47 \@ifpackagelater{cuted}{2021/10/04}{%
48 \relax
49 }{%
50 \PackageError{asmewide}{Your version of cuted.sty is too old. You can get an update at https://ctan.org/pkg/cuted}{You need an up-to-date version of cuted.sty to run asmewide.sty.}%
51 }
52
53 \RequirePackage{flushend}[2021/10/04]
54 %
55 % https://tex.stackexchange.com/a/43541/119566
56 \def\@getcl@ss#1.cls#2\relax{\def\@currentclass{#1}}
57 \def\@getclass{\expandafter\@getcl@ss\@filelist\relax}
58 \@getclass
59 \typeout{Running asmewide.sty with the \@currentclass\space class.}
60 %
61 \newbox\@TopLeader
62 \newbox\@BottomLeader
63 \newlength\savparskip \setlength\savparskip{\parskip}
64 \newlength\@RuleWidth
65 \appto\maketitle{\setlength\@RuleWidth{\dimexpr(\columnwidth+0.5\columnsep-1pt)}}% do this after entering twocolumn, in \maketitle. 2025/01/22
66 \newlength\@TopSpace \setlength\@TopSpace{0ex}
67 \newlength\@TopCorr \setlength\@TopCorr{-5pt}
68 \def\@asmeindent{3.5mm}
69 \def\@TopRuleWeight{0.5pt}
70 \def\@BottomRuleWeight{0.5pt}
71 \def\@DSS{5}% default stripsep
72 %
73 \@ifclassloaded{asmeconf}{%
74 \setlength\@TopCorr{-1ex}% keep \abovedisplayskip since text could start the page
75 \setlength\@TopSpace{1ex}% provide space apparently lost with cuted.sty in asmeconf.cls
76 \def\@asmeindent{0.25in}% asmeconf
77 }{\relax}
78
79 \@ifclassloaded{asmejour}{%
80 \AtBeginDocument{\setlength\@RuleWidth{\columnwidth}}
81 \setlength\@TopCorr{-9pt}% asmejour
82 \def\@BottomRuleWeight{1pt}% asmejour
83 \def\@DSS{10}% default stripsep, asmejour
84 }{\relax}
85 %
86 % Set ascenders and descenders 1.2 times greater than \baselineskip
87 \NewDocumentCommand\@SetTopLeader{}{% NB: boxes are cleared after they are used; this command is issued once with each widetext environment
88 \setbox\@TopLeader\vbox{%
89 \hbox to \@RuleWidth{%
90 \leaders\hrule height\@TopRuleWeight \hfil
91 \vrule height 1.2\baselineskip width\@TopRuleWeight}
92 }
93 }
94 \NewDocumentCommand\@TopLine{}{%
95 \vskip\@TopSpace
96 \dimen@\ht\@TopLeader\advance\dimen@\dp\@TopLeader
97 \cleaders\box\@TopLeader\vskip\dimen@
98 }
99 \NewDocumentCommand\@SetBottomLeader{}{%
100 \setbox\@BottomLeader\hbox to \@RuleWidth{%
101 \vrule depth 1.2\baselineskip width\@BottomRuleWeight
102 \leaders\hrule height\@BottomRuleWeight \hfil
103 }
104 }
105 \NewDocumentCommand\@BottomLine{}{%
106 \par
107 \vskip 3pt% provide some space between low equation numbers and rule
108 \setbox\@BottomLeader\vbox{%
109 \hbox to \textwidth{\hfil\box\@BottomLeader}%
110 }%
111 \dimen@\ht\@BottomLeader\advance\dimen@\dp\@BottomLeader
112 \cleaders\box\@BottomLeader\vskip\dimen@
113 \vskip -1.5pt% reduce trailing separation w.r.t. baseline when \stripsep = 0
114 }
115 \preCutedStrip={\@TopLine}
116 \postCutedStrip={\@BottomLine}
117 \DeclareDocumentEnvironment{widetext}{O{\@DSS}o}{%
118 \@SetTopLeader
119 \@SetBottomLeader
120 \notblank{#1}{%
121 \setlength{\stripsep}{#1pt plus 5pt minus 5pt}
122 }{
123 \setlength{\stripsep}{\@DSS pt plus 5pt minus 5pt}
124 }
125 \ifstrequal{#2}{t}{\setbox\@BottomLeader\vbox{}}{%
126 \ifstrequal{#2}{b}{\setbox\@TopLeader\vbox{\vskip \@TopCorr}}{%cuted inserts some additional space, we remove here
127 \ifstrequal{#2}{n}{\setbox\@TopLeader\vbox{\vskip \@TopCorr}\setbox\@BottomLeader\vbox{}}{\relax}
128 }
129 }
130 \begin{strip}
131 \setlength\parindent{\@asmeindent}% strip makes parindent zero; enlarge for ASME
132 \setlength\parskip{\savparskip}% strip makes \parskip zero w/o glue; set to match main text
133 }{%
134 \end{strip}\ignorespacesafterend
135 }
136 %%
137 \endinput
138 %%
139 %% End of file `asmewide.sty'.