| 1 |
% \iffalse meta-comment -*- mode: doctex -*- |
| 2 |
% |
| 3 |
% ullrcorners: draw corners on the upper left and lower right sides of |
| 4 |
% a word |
| 5 |
% |
| 6 |
% Copyright (C) 2025 Vincent Goulet |
| 7 |
% |
| 8 |
% This file may be distributed and/or modified under the conditions |
| 9 |
% of the LaTeX Project Public License, either version 1.3c of this |
| 10 |
% license or (at your option) any later version. The latest version |
| 11 |
% of this license is in: |
| 12 |
% |
| 13 |
% http://www.latex-project.org/lppl.txt |
| 14 |
% |
| 15 |
% This work has the LPPL maintenance status `maintained'. |
| 16 |
% |
| 17 |
% The Current Maintainer of this work is Vincent Goulet |
| 18 |
% <[email protected]>. |
| 19 |
% |
| 20 |
% This work consists of ullrcorners.dtx and the derived files. |
| 21 |
% \fi |
| 22 |
% |
| 23 |
% \iffalse |
| 24 |
%<*dtx> |
| 25 |
\ProvidesFile{ullrcorners.dtx} |
| 26 |
%</dtx> |
| 27 |
%<package>\NeedsTeXFormat{LaTeX2e} |
| 28 |
%<package>\ProvidesPackage{ullrcorners} |
| 29 |
%<*package> |
| 30 |
[2025/05/16 v1.0 ullrcorners] |
| 31 |
%</package> |
| 32 |
%<*driver> |
| 33 |
\documentclass[11pt,x11names]{ltxdoc} |
| 34 |
\usepackage{natbib} |
| 35 |
\usepackage{ullrcorners} |
| 36 |
\usepackage{enumitem} |
| 37 |
\usepackage{pict2e} |
| 38 |
\usepackage{metalogo} |
| 39 |
\def\changes#1#2#3{\glossary{#1>#3}} % simplified |
| 40 |
\DisableCrossrefs |
| 41 |
\CodelineNumbered |
| 42 |
\RecordChanges |
| 43 |
|
| 44 |
%% Configuration of the glossary |
| 45 |
\def\glossaryname{Version history} |
| 46 |
\GlossaryPrologue{\section*{\glossaryname}% |
| 47 |
\addcontentsline{toc}{section}{\glossaryname}} |
| 48 |
|
| 49 |
%% Fonts |
| 50 |
\iftutex |
| 51 |
\RequirePackage{microtype} |
| 52 |
\RequirePackage{fontspec} |
| 53 |
\RequirePackage{unicode-math} |
| 54 |
\setmainfont{STIXTwoText} |
| 55 |
[ |
| 56 |
Extension = .otf, |
| 57 |
UprightFont = *-Regular, |
| 58 |
BoldFont = *-SemiBold, |
| 59 |
ItalicFont = *-Italic, |
| 60 |
BoldItalicFont = *-SemiBoldItalic, |
| 61 |
Ligatures = TeX, |
| 62 |
] |
| 63 |
\setmathfont{STIXTwoMath-Regular} |
| 64 |
[ |
| 65 |
Extension = .otf, |
| 66 |
bold-style = TeX |
| 67 |
] |
| 68 |
\else |
| 69 |
\RequirePackage{microtype} |
| 70 |
\RequirePackage[utf8]{inputenc} |
| 71 |
\RequirePackage[T1]{fontenc} |
| 72 |
\RequirePackage{stix2} |
| 73 |
\fi |
| 74 |
\RequirePackage[medium,lining,scale=0.90]{FiraMono} |
| 75 |
|
| 76 |
%% Colors |
| 77 |
\usepackage{xcolor} |
| 78 |
\definecolor{link}{rgb}{0,0.4,0.6} % internal links |
| 79 |
\definecolor{url}{rgb}{0.6,0,0} % external links |
| 80 |
\definecolor{citation}{rgb}{0,0.5,0} % citations |
| 81 |
\colorlet{codebg}{LightYellow1} % code background |
| 82 |
\colorlet{ullrcornerscolor}{Snow4} % corners |
| 83 |
|
| 84 |
%% New \DescribeMacro type environment for colors |
| 85 |
\NewDocElement[envlike,notoplevel]{Colors}{colors} |
| 86 |
|
| 87 |
%% Hyperlinks |
| 88 |
\usepackage{hypdoc} |
| 89 |
\hypersetup{% |
| 90 |
pdftitle={Guide to the package ullrcorners}, |
| 91 |
pdfauthor={Vincent Goulet}, |
| 92 |
colorlinks = true, |
| 93 |
linktocpage = true, |
| 94 |
urlcolor = {url}, |
| 95 |
linkcolor = {link}, |
| 96 |
citecolor = {citation}, |
| 97 |
pdfpagemode = {UseOutlines}, |
| 98 |
pdfstartview = {Fit}} |
| 99 |
|
| 100 |
%% Source code |
| 101 |
\usepackage{listings} |
| 102 |
\lstset{% |
| 103 |
basicstyle=\ttfamily, |
| 104 |
showstringspaces=false, |
| 105 |
backgroundcolor=\color{codebg}, |
| 106 |
frame=leftline, |
| 107 |
framerule=2pt, |
| 108 |
framesep=5pt, |
| 109 |
xleftmargin=7.4pt |
| 110 |
} |
| 111 |
|
| 112 |
%% Package name |
| 113 |
\newcommand*\pkgname{ullrcorners} |
| 114 |
\newcommand*\ullrpkg{\pkg{\pkgname}} |
| 115 |
|
| 116 |
%% Redefine \year and define \isodate using information from |
| 117 |
%% \filedate instead of using compilation time |
| 118 |
\def\parsedate#1/#2/#3\relax{\def\year{#1}\def\isodate{#1-#2-#3}} |
| 119 |
\def\parseversion v#1.#2\relax{\def\version{#1.#2}} |
| 120 |
|
| 121 |
%% Utility macro |
| 122 |
\let\pkg\textbf |
| 123 |
|
| 124 |
\begin{document} |
| 125 |
\DocInput{ullrcorners.dtx} |
| 126 |
\end{document} |
| 127 |
%</driver> |
| 128 |
% \fi |
| 129 |
% ^^A NOTE: The first three "versions" are in the project |
| 130 |
% ^^A https://gitlab.com/vigou3/programmer-avec-r |
| 131 |
% \changes{0.1}{2019-11-28}{First private version.} |
| 132 |
% \changes{0.2}{2019-12-09}{Fix usage of the main macro at the |
| 133 |
% beginning of a paragraph.} |
| 134 |
% \changes{0.3}{2024-12-13}{Fix underfull horizontal boxes caused by |
| 135 |
% the upper left corner.} |
| 136 |
% \changes{1.0}{2025-05-16}{First public release.} |
| 137 |
% |
| 138 |
% \GetFileInfo{ullrcorners.dtx} |
| 139 |
% \expandafter\parsedate\filedate\relax |
| 140 |
% \expandafter\parseversion\fileversion\relax |
| 141 |
% |
| 142 |
% \title{{% |
| 143 |
% \setlength\ullrcornerslinewidth{1.02pt} |
| 144 |
% \setlength\ullrcornershlength{0.6ex} |
| 145 |
% \setlength\ullrcornersvlength{1.5\ullrcornershlength} |
| 146 |
% \setlength\ullrcornersvgap{\ullrcornerslinewidth} |
| 147 |
% \setlength\ullrcornershgap{\ullrcornersvgap} |
| 148 |
% \ullrcorners{ullrcorners}}} |
| 149 |
% \author{Vincent Goulet \\ |
| 150 |
% \href{mailto:[email protected]}{\url{[email protected]}}} |
| 151 |
% \date{Version~\version, \isodate} |
| 152 |
% \maketitle |
| 153 |
% |
| 154 |
% \section{Package features} |
| 155 |
% \label{sec:features} |
| 156 |
% |
| 157 |
% {\ullrpkg} provides a command to surround a word or a sequence or |
| 158 |
% words by small corners on the upper left and lower right sides, like |
| 159 |
% \ullrcorners{this}. The typographical convention is inspired by |
| 160 |
% \citet{Friedl:regex:2006}, where it is used to delimit regular |
| 161 |
% expressions. |
| 162 |
% |
| 163 |
% \begin{DescribeMacro}{\ullrcorners} |
| 164 |
% The command |\ullrcorners| surrounds the word or sequence of words |
| 165 |
% in argument by corners. The example above is typeset using: |
| 166 |
% \iffalse |
| 167 |
%<*example> |
| 168 |
% \fi |
| 169 |
\begin{lstlisting} |
| 170 |
\ullrcorners{this} |
| 171 |
\end{lstlisting} |
| 172 |
% \iffalse |
| 173 |
%</example> |
| 174 |
% \fi |
| 175 |
% \end{DescribeMacro} |
| 176 |
% |
| 177 |
% \begin{DescribeColors}{ullrcornerscolor} |
| 178 |
% If, and only if, a color |ullrcornerscolor| is defined in the |
| 179 |
% preamble, the package will use this color instead of the default |
| 180 |
% text color to draw the corners. Therefore, the example above is |
| 181 |
% really obtained by loading \pkg{xcolor} with the option |
| 182 |
% |x11names|, and by defining the color in the preamble: |
| 183 |
% \iffalse |
| 184 |
%<*example> |
| 185 |
% \fi |
| 186 |
\begin{lstlisting} |
| 187 |
\colorlet{ullrcornerscolor}{Snow4} |
| 188 |
\end{lstlisting} |
| 189 |
% \iffalse |
| 190 |
%</example> |
| 191 |
% \fi |
| 192 |
% \end{DescribeColors} |
| 193 |
% |
| 194 |
% That is pretty much all there is in terms of package features. |
| 195 |
% |
| 196 |
% \section{Customization} |
| 197 |
% \label{sec:customization} |
| 198 |
% |
| 199 |
% You may customize the appearance of the corners by redefining the |
| 200 |
% following lengths using |\setlength| (see \autoref{fig:parameters} |
| 201 |
% for a visual summary): |
| 202 |
% \begin{description}[font=\normalfont\ttfamily,noitemsep] |
| 203 |
% \item[\ttfamily\string\ullrcornerslinewidth] |
| 204 |
% (default $0.8$~pt) \\ |
| 205 |
% rule thickness of the corners; |
| 206 |
% \item[\ttfamily\string\ullrcornershlength] |
| 207 |
% (default $0.6$~ex) \\ |
| 208 |
% length of the horizontal rules; |
| 209 |
% \item[\ttfamily\string\ullrcornersvlength] |
| 210 |
% (default $1.5$ times |\ullrcornershlength|) \\ |
| 211 |
% length of the vertical rules; |
| 212 |
% \item[\ttfamily\string\ullrcornersvgap] |
| 213 |
% (default |\ullrcornerslinewidth|) \\ |
| 214 |
% space between the horizontal rules and the text; |
| 215 |
% \item[\ttfamily\string\ullrcornershgap] |
| 216 |
% (default |\ullrcornersvgap|) \\ |
| 217 |
% space between the vertical rules and the text. |
| 218 |
% \end{description} |
| 219 |
% |
| 220 |
% The package does not provide support for asymetrical upper left and |
| 221 |
% lower right corners. |
| 222 |
% |
| 223 |
% \begin{figure} |
| 224 |
% \centering |
| 225 |
% \setlength{\unitlength}{20mm} |
| 226 |
% ^^A picture pretty much to scale using 1mm = 2.84526pt and |
| 227 |
% ^^A 1ex = 4.71945pt = 1,65871mm in 11pt font size |
| 228 |
% ^^A (https://tex.stackexchange.com/a/8337) |
| 229 |
% \begin{picture}(5.25,2.5)(-2.5,0.5) |
| 230 |
% \small |
| 231 |
% ^^A text outline |
| 232 |
% \put(0,2){\line(1,0){2.5}} |
| 233 |
% \put(0,2){\line(0,-1){1.5}} |
| 234 |
% |
| 235 |
% ^^A top and left rules |
| 236 |
% \put(-0.56234,2.28117){\rule{0.99523\unitlength}{0.28117\unitlength}} |
| 237 |
% \put(-0.56234,2.28117){\rule[-1.21168\unitlength]{0.28117\unitlength}{1.49285\unitlength}} |
| 238 |
% |
| 239 |
% ^^A length of top rule |
| 240 |
% \multiput(-0.56234,2.61234)(0.99523,0){2}{\line(0,1){0.2}} |
| 241 |
% \Vector(-0.06473,2.71234)(-0.56234,2.71234) |
| 242 |
% \Vector(-0.06473,2.71234)(0.43289,2.71234) |
| 243 |
% \put(-0.06473,3.01234){\makebox(0,0){\texttt{\string\ullrcornershlength}}} |
| 244 |
% \Vector(-0.06473,2.91234)(-0.06473,2.71234) |
| 245 |
% |
| 246 |
% ^^A width of top rule |
| 247 |
% \multiput(0.48289,2.28117)(0,0.28117){2}{\line(1,0){0.2}} |
| 248 |
% \put(0.58289,2.421755){\vector(0,-1){0.140585}} |
| 249 |
% \put(0.58289,2.421755){\vector(0,1){0.140585}} |
| 250 |
% \put(0.68289,2.421755){\makebox(0,0)[l]{\texttt{\string\ullrcornerslinewidth}}} |
| 251 |
% |
| 252 |
% ^^A vertical gap |
| 253 |
% \put(0.58289,2.140585){\vector(0,-1){0.140585}} |
| 254 |
% \put(0.58289,2.140585){\vector(0,1){0.140585}} |
| 255 |
% \put(0.68289,2.140585){\makebox(0,0)[l]{\texttt{\string\ullrcornersvgap}}} |
| 256 |
% |
| 257 |
% ^^A length of left rule |
| 258 |
% \multiput(-0.81234,2.28117)(0,-1.21168){2}{\line(1,0){0.2}} |
| 259 |
% \put(-0.71234,1.67533){\vector(0,-1){0.60584}} |
| 260 |
% \put(-0.71234,1.67533){\vector(0,1){0.60584}} |
| 261 |
% \put(-0.81234,1.67533){\makebox(0,0)[r]{\texttt{\string\ullrcornersvlength}}} |
| 262 |
% |
| 263 |
% ^^A horizontal gap |
| 264 |
% \put(-0.28117,1,01949){\line(0,-1){0.2}} |
| 265 |
% \put(-0.140585,0.91949){\vector(1,0){ 0.140585}} |
| 266 |
% \put(-0.140585,0.91949){\vector(-1,0){0.140585}} |
| 267 |
% \put(-0.5321755,0.71949){\makebox(0,0)[r]{\texttt{\string\ullrcornershgap}}} |
| 268 |
% \Vector(-0.140585,0.81949)(-0.140585,0.91949) |
| 269 |
% \qbezier(-0.140585,0.81949)(-0.140585,0.71949)(-0.240585,0.71949) |
| 270 |
% \Line(-0.4321755,0.71949)(-0.240585,0.71949) |
| 271 |
% \end{picture} |
| 272 |
% \caption{Parameters of the corners (shown here for the upper left |
| 273 |
% corner)} |
| 274 |
% \label{fig:parameters} |
| 275 |
% \end{figure} |
| 276 |
% |
| 277 |
% \MaybeStop{% |
| 278 |
% \begin{thebibliography}{1} |
| 279 |
% \bibitem[{Friedl(2006)}]{Friedl:regex:2006} |
| 280 |
% Friedl, J. E.~F. (2006). |
| 281 |
% \newblock \emph{Mastering Regular Expressions}. |
| 282 |
% \newblock 3rd ed. O'Reilly {M}edia. |
| 283 |
% \newblock ISBN 0-59652812-4. |
| 284 |
% \end{thebibliography} |
| 285 |
% \PrintChanges |
| 286 |
% } |
| 287 |
% |
| 288 |
% \appendix |
| 289 |
% |
| 290 |
% ^^A >>>>> Start of the code of the package |
| 291 |
%% \section{Implementation} |
| 292 |
% \label{sec:implementation} |
| 293 |
% |
| 294 |
% First, we define the lengths needed by the package and set their |
| 295 |
% default values. |
| 296 |
% |
| 297 |
%\iffalse |
| 298 |
%<*package> |
| 299 |
%\fi |
| 300 |
% \begin{macrocode} |
| 301 |
\newlength\ullrcornerslinewidth |
| 302 |
\newlength\ullrcornershlength |
| 303 |
\newlength\ullrcornersvlength |
| 304 |
\newlength\ullrcornersvgap |
| 305 |
\newlength\ullrcornershgap |
| 306 |
\setlength\ullrcornerslinewidth{0.8pt} |
| 307 |
\setlength\ullrcornershlength{0.6ex} |
| 308 |
\setlength\ullrcornersvlength{1.5\ullrcornershlength} |
| 309 |
\setlength\ullrcornersvgap{\ullrcornerslinewidth} |
| 310 |
\setlength\ullrcornershgap{\ullrcornersvgap} |
| 311 |
% \end{macrocode} |
| 312 |
% |
| 313 |
% Second, we will need a command to set the color of the corners. By |
| 314 |
% default, this command does nothing. However, if a color |
| 315 |
% |ullrcornerscolor| is defined at the beginning of the document, then |
| 316 |
% the command is redefined as a call to |\color| (this assumes that a |
| 317 |
% color package is loaded). |
| 318 |
% \changes{1.0}{2025-05-16}{Implementation: the main macro now has |
| 319 |
% only one argument and uses the color \texttt{ullrcornerscolor} if it |
| 320 |
% is defined in the preamble.} |
| 321 |
% \begin{macrocode} |
| 322 |
\newcommand*\ullrc@color{\relax} |
| 323 |
\AtBeginDocument{% |
| 324 |
\@ifundefined{\string\color@ullrcornerscolor}{}{% |
| 325 |
\renewcommand\ullrc@color{\color{ullrcornerscolor}}}} |
| 326 |
% \end{macrocode} |
| 327 |
% |
| 328 |
% Finally, we define the robust user command |\ullrcorners|. It draws |
| 329 |
% the corners using {\TeX} rules and boxes. |
| 330 |
% \changes{1.0}{2025-05-16}{Implementation: fix boxes such that the |
| 331 |
% horizontal space between the text and the corners really is |
| 332 |
% \cs{ullrcornershgap} without hacks.} |
| 333 |
% \changes{1.0}{2025-05-16}{Implementation: declare the main macro as |
| 334 |
% a robust command.} |
| 335 |
% \begin{macrocode} |
| 336 |
\DeclareRobustCommand{\ullrcorners}[1]{% |
| 337 |
\setbox\z@\hbox{\kern\ullrcornershgap #1\kern\ullrcornershgap}% |
| 338 |
\dimen\z@=\dimexpr\ullrcornerslinewidth+\ullrcornersvgap+\dp\z@ |
| 339 |
\setbox\tw@\hbox to\dimexpr\wd\z@+2\ullrcornerslinewidth{% |
| 340 |
\hfil% |
| 341 |
\vbox{% |
| 342 |
\ullrc@color% |
| 343 |
\hbox to\ullrcornershlength{% |
| 344 |
\hfil\vrule \@height\ullrcornersvlength \@width\ullrcornerslinewidth% |
| 345 |
}% |
| 346 |
\hrule \@height\ullrcornerslinewidth |
| 347 |
}% |
| 348 |
}% |
| 349 |
\dimen\tw@=\dimexpr\ullrcornersvgap-\ullrcornersvlength |
| 350 |
\leavevmode% |
| 351 |
\vbox{% |
| 352 |
\offinterlineskip |
| 353 |
\vbox{% |
| 354 |
\ullrc@color% |
| 355 |
\hrule \@height\ullrcornerslinewidth |
| 356 |
\hbox to\ullrcornershlength{% |
| 357 |
\vrule \@height\ullrcornersvlength \@width\ullrcornerslinewidth\hfil |
| 358 |
}% |
| 359 |
} |
| 360 |
\kern\dimen\tw@ |
| 361 |
\hbox{\kern\ullrcornerslinewidth\box\z@}% |
| 362 |
\kern\dimen\tw@ |
| 363 |
\hbox{\raise -\dimen\z@\box\tw@}% |
| 364 |
}% |
| 365 |
} |
| 366 |
% \end{macrocode} |
| 367 |
% \iffalse |
| 368 |
%</package> |
| 369 |
%\fi |
| 370 |
% |
| 371 |
% \Finale |
| 372 |
\endinput |