Files
PrimeTeX/packages/Marginalia.sty
Joshua Lucas d1fd2fef22 - Fix WrapBoxout.
- Migrate from wrapfig2 to wrapstuff.
- Miscellaneous improvements.
2025-09-10 16:32:35 -05:00

94 lines
2.2 KiB
TeX

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{PrimeTeX/packages/Marginalia}[2025-07-09]
% Allow hyphenation in narrow margin paragraphs.
\RequirePackage{ragged2e}
\RequirePackage{marginalia}
\marginaliasetup{
ysep = {\parskip},
ysep page bottom = {
- 1in % Top gutter
+ \paperheight
- \voffset
- \topmargin
- \headheight
- \headsep
- \textheight
},
yshift = {7pt}, % Just a magic number that lines up margin notes with their reference.
style recto outer = {\RaggedRight\small\color{marginText}},
style verso outer = {\RaggedLeft\small\color{marginText}},
}
\NewDocumentCommand{\MarginHyperSetup}{}{
\ifthenelse{\boolean{isElectronic}}{
\hypersetup{allcolors = link}
}{
\hypersetup{allcolors = marginText}
}
}
% Put a glossary definition in a margin paragraph.
\NewDocumentCommand{\mdef}{O{} m m}{%
\index{\glsentryname{#2}}% Add a reference to this in the index.
\strong{#3{#2}}% This is the text that appears on the page.
\marginalia[#1]{%
\MarginHyperSetup%
\strong{\Glsentryname{#2}:} % Create the title of the margin note.
\glsdesc*{#2}% Create the text of the margin note.
}%
}
\NewDocumentCommand{\margindef}{O{} m}{%
\mdef[#1]{#2}{\gls}%
}
\NewDocumentCommand{\Margindef}{O{} m}{%
\mdef[#1]{#2}{\Gls}%
}
\NewDocumentCommand{\margindefpl}{O{} m}{%
\mdef[#1]{#2}{\glspl}%
}
\NewDocumentCommand{\Margindefpl}{O{} m}{%
\mdef[#1]{#2}{\Glspl}%
}
% Put a footnote in a margin paragraph.
\NewDocumentCommand{\mnote}{O{} +m}{%
\footnotemark%
\marginalia[#1]{%
\MarginHyperSetup%
\footnotemark[\value{footnote}]#2%
}%
}
\NewDocumentCommand{\marginfig}{O{} m m +m}{%
% Syntax:
% \marginfig[
% (width|height)=lengthvalue, or any other optional \includegraphics
% parameters
% ]{
% graphic_file_name
% }{
% label
% }{
% caption
% }
%
% This strut ensures that the margin figure is counted as part of the
% following paragraph and is vertically aligned with it.
\strut%
\marginalia{%
\MarginHyperSetup%
% \captionsetup{%
% type = figure,%
% justification = RaggedOutside,%
% }%
\begin{MyCaption}[
format={\RaggedOutside\small\color{caption}}
]{fig:#3}{#4}
\Centering\includegraphics[keepaspectratio,#1]{#2}%
\end{MyCaption}
% \noindent\captionof{figure}{#4}%
% \label{fig:#3}%
}%
}