% \iffalse meta-comment
% File: vexillology.dtx Copyright (C) 2026 Karl D. Hammond
%
% Karl D. Hammond
% CTAN and TeX StackExchange user karlh
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is K. D. Hammond.
%
% This work consists of the files vexillology.dtx and vexillology.ins
% and the derived files vexillology.sty and vexillology.pdf.
% \fi
%
% \iffalse
%<*driver>
\ProvidesFile{vexillology.dtx}
%</driver>
%
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\RequirePackage{tikz}
%<package>\ProvidesPackage{vexillology}
%<*package>
    [2026/01/15 v1.0.0 vexillogical symbols]
%</package>
%<*driver>
\documentclass[12pt,letterpaper]{ltxdoc}
\usepackage[margin=1in]{geometry}
\usepackage[T1]{fontenc}
\usepackage{newpxtext,newpxmath}
\usepackage{booktabs}
\usepackage{listings}
\usepackage[svgnames]{xcolor}
\usepackage{tikz}
\usepackage[labelfont=bf,labelsep=period,font=small]{caption}
\usepackage{worldflags}
\GetFileInfo{vexillology.dtx}
\usepackage{vexillology}[\filedate\space\fileversion]
\DisableCrossrefs
\CodelineIndex
\PageIndex
\CodelineNumbered
\RecordChanges
\let\env\texttt
\let\pkg\textsf
\IndexPrologue{\section*{Index}%
                 \markboth{Index}{Index}%
                 Numbers written in italics refer to the page
                 where the corresponding entry is described;
                 numbers underlined refer to the code line
                 of the definition.}
\begin{document}
  \DocInput{vexillology.dtx}
\end{document}
%</driver>
% \fi
%
%^^A \CheckSum{}
%
% \CharacterTable
% {Upper-case   \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%  Lower-case   \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%  Digits       \0\1\2\3\4\5\6\7\8\9
%  Exclamation     \!      Double quote    \"      Hash (number)   \#
%  Dollar          \$      Percent         \%      Ampersand       \&
%  Acute accent    \'      Left paren      \(      Right paren     \)
%  Asterisk        \*      Plus            \+      Comma           \,
%  Minus           \-      Point           \.      Solidus         \/
%  Colon           \:      Semicolon       \;      Less than       \<
%  Equals          \=      Greater than    \>      Question mark   \?
%  Commercial at   \@      Left bracket    \[      Backslash       \\
%  Right bracket   \]      Circumflex      \^      Underscore      \_
%  Grave accent    \`      Left brace      \{      Vertical bar    \|
%  Right brace     \}      Tilde           \~}
%
% \changes{v1.0.0}{2026/01/15}{Initial public release}
%
% \providecommand*{\TikZ}{Ti\emph{k}Z}
% \hypersetup{urlcolor=DarkBlue,linkcolor=DarkRed}
%
% \lstset{%
%   basicstyle=\ttfamily\footnotesize,
%^^A   columns=flexible,
%   language={[LaTeX2e]TeX},
%^^A   texcsstyle=*\bfseries\color{emphcolor},
%   keywordstyle=[2]\color{mathcolor},
%   keywordstyle=[3]\color{red},
%   commentstyle=\color{gray},
%   moretexcs={worldflag,vexcivilflag,vexstateflag,vexwarflag,%
%     vexcivilensign,vexstateensign,vexwarensign,vexusage,%
%     vexgrid,vexgridextended,%
%     vexnormal,vexproposed,vexreconstruction,vexreverse,vexvariant,%
%     vexalternative,vexdefacto,vexreverseisdifferent,vexsinisterhoist,%
%     vexauthorized,vexhistorical,vexreverseismirror,vexreverseiscongruent,%
%     vexnormalvertical,vexobversevertical,vexrotatevertical,%
%     vexunknownvertical,vexonlyvertical,vexnorotating,vexunauthorized,},%
% }
% \newcommand\command{\lstinline[basicstyle=\ttfamily,texcsstyle=*\bfseries\color{MidnightBlue}]}
% \newcommand\docstripworldflag[2][]%
%   {\bgroup\catcode`\%=14\worldflag[#1]{#2}\egroup}
%
% \GetFileInfo{vexillology.dtx}
% \title{The \textsf{vexillology} package\thanks{This document corresponds to
%       \pkg{vexillology}~\fileversion, dated \filedate.}}
% \author{Karl D. Hammond}
% \date{\filedate}
% \maketitle
%
% \begin{abstract}
% This package implements symbols used by vexillologists (people who study
% flags) to indicate certain aspects of flags, such as where they are used,
% who uses them, and what they look like. The package uses \TikZ\ to draw the
% symbols, whose heights scale with the font size.
% \end{abstract}
%
% \section{Introduction}
% In the 1970s, Dr.~Whitney Smith, vexillologist and founder of the North
% American Vexillogical Association, created a series of symbols for use in
% his books on flags that identify how flags are used. These symbols include
% whether the particular image being shown is used as the civilian flag
% rather than for state or military purposes, as well as whether they are
% officially designed by law or other government policy or simply commonly
% used, how they appear when hung vertically, and whether the flag is
% currently used or has been/was officially adopted.
%
% The symbols were proposed (though never officially adopted) by the
% International Federation of Vexillogical Associations (FIAV) in the late
% 1970s, and the symbol set has been supplemented on occasion.
% In particular, \v Zeljko Heimer added the symbols \vexnormal\ and
% \vexhistorical\ to differentiate flags that were currently in use from
% historical, no-longer-in-use flags. The package author also added the
% \vexobversevertical\ symbol for clarity.\footnote{The author has asked
%   in various places what the difference between \vexrotatevertical\ and
%   \vexnorotating\ is, but it is not entirely clear. The
%   interpretations herein represent his understanding at the time of the
%   most recent update.}
%
% A proposal exists [A.~Pandey, ``Proposal to Encode Vexillology Symbols in
%   UNICODE,''
% \url{https://www.unicode.org/L2/L2024/24245-vexillology-symbols.pdf},
%   2024] to encode the symbols in this document in UNICODE\@. However, at
% the time of writing, this has not been done. If this proposal is accetped,
% a package option will be introduced to use the UNICODE characters directly.
%
% \section{Status and Design Symbols} \label{sec:design}
% The first set of symbols describes the state of recognition for a flag and
% its design. The symbols are included in Table~\ref{table:design}.
% \begin{table}
%   \caption{Symbols used to denote the design and/or official status of
%     a flag or ensign.}
%   \label{table:design}
%   \leavevmode
%   \SpecialMacroIndex{\vexnormal}\relax
%   \SpecialMacroIndex{\vexproposed}\relax
%   \SpecialMacroIndex{\vexreconstruction}\relax
%   \SpecialMacroIndex{\vexreverse}\relax
%   \SpecialMacroIndex{\vexvariant}\relax
%   \SpecialMacroIndex{\vexvexalternative}\relax
%   \SpecialMacroIndex{\vexdefacto}\relax
%   \SpecialMacroIndex{\vexreverseisdifferent}\relax
%   \SpecialMacroIndex{\vexsinisterhoist}\relax
%   \SpecialMacroIndex{\vexauthorized}\relax
%   \SpecialMacroIndex{\vexhistorical}\relax
%   \SpecialMacroIndex{\vexreverseismirror}\relax
%   \SpecialMacroIndex{\vexreverseiscongruent}\relax
%   \SpecialMacroIndex{\vexnormalvertical}\relax
%   \SpecialMacroIndex{\vexobversevertical}\relax
%   \SpecialMacroIndex{\vexrotatevertical}\relax
%   \SpecialMacroIndex{\vexunknownvertical}\relax
%   \SpecialMacroIndex{\vexonlyvertical}\relax
%   \SpecialMacroIndex{\vexnorotating}\relax
%   \SpecialMacroIndex{\vexunauthorized}\relax
%   \centering\small
%   \begin{minipage}{\linewidth}\renewcommand*{\footnoterule}{\vskip-1ex}\relax
%   \centering
%   \begin{tabular}{l l p{8.4cm}}
%   \toprule
%     \textbf{Symbol} & \textbf{Macro}
%     & \multicolumn{1}{l}{\textbf{Meaning}} \\
%   \midrule
%     \vexnormal & \command"\vexnormal"
%       & Ordinary (\emph{de jure}) version of the flag, obverse side \\
%     \vexproposed & \command"\vexproposed" & Design was proposed, but
%       was never officially adopted \\
%     \vexreconstruction & \command"\vexreconstruction"
%       & Design is a reconstruction based on observations or descriptions \\
%     \vexreverse & \command"\vexreverse"
%       & Design shown is the reverse side \\
%     \vexvariant & \command"\vexvariant"
%       & Design shown is an acceptable variant of the ordinary design \\
%     \vexalternative & \command"\vexalternative"
%       & Design shown is one of several alternative versions that can be
%           displayed \\
%     \vexdefacto & \command"\vexdefacto"
%       & Design shown is the \emph{de facto} flag, widely used but not
%           officially adopted \\
%     \vexreverseisdifferent & \command"\vexreverseisdifferent"
%       & Flag has different designs on the obverse and the reverse sides \\
%     \vexsinisterhoist & \command"\vexsinisterhoist"
%       & Obverse side is meant to be hoisted with the pole on the observer's
%         right. \\
%     \vexauthorized & \command"\vexauthorized"
%       & Design is officially authorized by the applicable government
%       (unnecessary when \vexnormal\ is used) \\
%     \vexhistorical & \command"\vexhistorical"
%       & Design was used in the past, but is now abandoned. \\
%     \vexreverseismirror & \command"\vexreverseismirror"
%       & Reverse side is a mirror image of the obverse \\
%     \vexreverseiscongruent & \command"\vexreverseiscongruent"
%       & Reverse side is identical to the obverse \\
%     \vexnormalvertical & \command"\vexnormalvertical"
%       & Flag can be hung vertically by hanging with an ordinary pole, then
%         rotating 90\textdegree\ counterclockwise (reverse is face-up) \\
%     \vexobversevertical & \command"\vexobversevertical"
%       & Flag can be hung vertically by hanging with an ordinary pole, then
%         rotating 90\textdegree\ clockwise (obverse is face-up)\footnote{This
%           symbol is non-standard, but it is used here to differentiate, for
%           example, the flags of Canada and the United States, which show
%           their reverse when hung vertically, from Brazil or Nicaragua,
%           which show the obverse.} \\
%     \vexrotatevertical & \command"\vexrotatevertical"
%       & Design does not rotate with the flag when hanging vertically \\
%     \vexunknownvertical & \command"\vexunknownvertical"
%       & Information is not given or is not known for vertical display \\
%     \vexonlyvertical & \command"\vexonlyvertical"
%       & Flag [as shown] can only be hoisted vertically \\
%     \vexnorotating & \command"\vexnorotating"
%       & Design has no elements that can be rotated \\
%     \vexunauthorized & \command"\vexunauthorized"
%       & Flag is not officially authorized to represent the group or country
%     \\
%   \bottomrule
%   \end{tabular}
%   \end{minipage}
% \end{table}
% These symbols are typically used in tandem with the symbols in
% section~\ref{sec:usage}, so further discussion of them will be given in a
% later section for those that are not explained adequately in the table.
%
% \section{Usage Symbols} \label{sec:usage}
% In a second set of symbols, dots in a $3 \times 2$ grid denote the use of a
% flag. The top row represents land-based use, while the bottom shows maritime
% use. The first column denotes civilian (``civil'') use, the second column
% government (``state'') use, and the final column military (``war'') use;
% that is,
% \begin{center}
%   \begin{tikzpicture}
%     \begin{scope}[every node/.style={font=\tiny\color{white},
%       minimum size=0.75cm,circle,draw,fill,text width=0.7cm,inner sep=0pt,
%       align=center}]
%     \vexgrid
%     \node at (0.5,0.5) {civil flag};
%     \node at (1.5,0.5) {gov't flag};
%     \node at (2.5,0.5) {military flag};
%     \node at (0.5,-0.5) {civil ensign};
%     \node at (1.5,-0.5) {gov't ensign};
%     \node at (2.5,-0.5) {naval ensign};
%     \end{scope}
%     \begin{scope}[overlay]
%       \node [anchor=west] at (3.5, 0.5) {\emph{used on land}};
%       \node [anchor=west] at (3.5,-0.5) {\emph{used on water}};
%     \end{scope}
%   \end{tikzpicture}
% \end{center}
% Occasionally, an ``extended'' usage symbol is used, which has three rows:
% air, land, and water:
% \begin{center}
%   \begin{tikzpicture}
%     \begin{scope}[every node/.style={font=\tiny\color{white},
%       minimum size=0.75cm,circle,draw,fill,text width=0.7cm,inner sep=0pt,
%       align=center}]
%     \vexgridextended
%     \node at (0.5,1.5) {civil air ens.};
%     \node at (1.5,1.5) {state air ens.};
%     \node at (2.5,1.5) {war air ensign};
%     \node at (0.5,0.5) {civil flag};
%     \node at (1.5,0.5) {state flag};
%     \node at (2.5,0.5) {war flag};
%     \node at (0.5,-0.5) {civil ensign};
%     \node at (1.5,-0.5) {state ensign};
%     \node at (2.5,-0.5) {war ensign};
%     \end{scope}
%     \begin{scope}[overlay]
%       \node [anchor=west] at (3.5, 1.5) {\emph{used in the air}};
%       \node [anchor=west] at (3.5, 0.5) {\emph{used on land}};
%       \node [anchor=west] at (3.5,-0.5) {\emph{used on water}};
%     \end{scope}
%   \end{tikzpicture}
% \end{center}
% \DescribeMacro{\vexusage}
% These symbols are generated by the \command"\vexusage" command.
% The argument to \command"\vexusage" is a six-bit whole number (or, in the
% case of the extended usage symbol, a nine-bit whole number), with the
% least-significant bit denoting use as the civil flag. In the extended
% symbol, the three most significant bits are the air usage bits.
%
% For example, \command"\vexusage{23}" expands to
% \vexusage{23}, which indicates a flag used as the civil flag (bit~0, or
% $2^0=1$), the state flag (bit~1, or $2^1 = 2$), the war flag (bit~2,
% or $2^2 = 4$), and the state ensign (bit~5, or $2^5 = 16$), for a total of
% $2^0 + 2^1 + 2^2 + 2^5 = 23$.
%
% If the argument to \command"\vexusage" is 64 (i.e., $2^6$) or more, the
% extended symbol is assumed. For example, \command"\smash{\vexusage{66}}" produces
% \smash{\vexusage{66}}. To force a three-row symbol for an argument of 63 or
% less, use the starred form: \command"\smash{\vexusage*{23}}" expands to
% \smash{\vexusage*{23}}.
%
% The argument to \command"\vexusage" is parsed for addition and other
% operations, so it is valid to say \command"\vexusage{1+2+4+16}" instead of
% \command"\vexusage{23}". To avoid having to remember which bit is
% which---or do powers of 2\ in one's head---several macros are defined to
% make it easy to set only one or two bits. These macros are listed in
% Table~\ref{table:shortcuts}. Using those macros,
% \command"\vexusage{\vexcivilensign+\vexstateensign}", equivalent to
% \command"\vexusage{24}", yields \vexusage{\vexcivilensign+\vexstateensign}.
%
% \newcommand{\makearow}[1]{\texttt{\bfseries\color{MidnightBlue}\string #1} & #1 & \vexusage{#1}}
% \begin{table}
%   \caption{Shortcut macros to represent each bit in the
%     \texttt{\bfseries\color{MidnightBlue}\textbackslash vexusage} command
%     argument.}
%   \label{table:shortcuts}
%   \leavevmode
%   \SpecialMacroIndex{\vexcivilflag}\relax
%   \SpecialMacroIndex{\vexstateflag}\relax
%   \SpecialMacroIndex{\vexwarflag}\relax
%   \SpecialMacroIndex{\vexcivilensign}\relax
%   \SpecialMacroIndex{\vexstateensign}\relax
%   \SpecialMacroIndex{\vexwarensign}\relax
%   \SpecialMacroIndex{\vexcivilairensign}\relax
%   \SpecialMacroIndex{\vexstateairensign}\relax
%   \SpecialMacroIndex{\vexwarairensign}\relax
%   \SpecialMacroIndex{\vexnationalflag}\relax
%   \SpecialMacroIndex{\vexnationalensign}\relax
%   \SpecialMacroIndex{\vexnationalflagandensign}\relax
%   \SpecialMacroIndex{\vexnationaleverything}\relax
%   \centering\small
%   \begin{tabular}{l l l}
%   \toprule
%     \textbf{Macro} & \textbf{Expansion}
%   & \textbf{Result of} \command"\vexusage"\{\emph{macro}\} \\
%   \midrule
%     \multicolumn{3}{l}{\textbf{Single-Bit Shortcuts}} \\
%   \midrule
%     \makearow{\vexcivilflag} \\
%     \makearow{\vexstateflag} \\
%     \makearow{\vexwarflag} \\
%     \makearow{\vexcivilensign} \\
%     \makearow{\vexstateensign} \\
%     \makearow{\vexwarensign} \\
%     \makearow{\vexcivilairensign} \\
%     \makearow{\vexstateairensign} \\
%     \makearow{\vexwarairensign} \\
%   \midrule
%     \multicolumn{3}{l}{\textbf{Multi-Bit Shortcuts}} \\
%   \midrule
%     \makearow{\vexnationalflag} \\
%     \makearow{\vexnationalensign} \\
%     \makearow{\vexnationalflagandensign} \\
%     \makearow{\vexnationaleverything} \\
%   \bottomrule
%   \end{tabular}
% \end{table}
%
% \clearpage
% \section{Using the Symbols}
%^^A NOTE: The flags used in this section may or may not be implemented in
%^^A       published version of worldflags and likely require either the use
%^^A       of images included via \includegraphics or the author's personal
%^^A       (unpublished) flag description files.
% \flagsdefault[width=2cm]
% As an example of the use of these symbols, the flags of Barbados, China, and
% the Dominican Republic are shown below:
% \begin{center}
%   \begin{minipage}[t]{0.25\linewidth}\centering
%     \worldflag{BB} \\
%     Barbados \vexusage{31} \vexnormal\ \vexnormalvertical
%   \end{minipage}
%   \begin{minipage}[t]{0.25\linewidth}\centering
%     \worldflag{CN} \\
%     China \vexusage{27} \vexnormal\ \vexreverseismirror\ \vexobversevertical
%   \end{minipage}
%   \begin{minipage}[t]{0.4\linewidth}\centering
%     \worldflag{DO} \\
%     Dominican Republic \vexusage{54}
%       \vexnormal\ \vexreverseismirror\ \vexrotatevertical
%   \end{minipage}
% \end{center}
% The symbols indicate that Barbados uses the flag variant shown for all
% purposes except its navy; China uses this flag variant for all civilian and
% state purposes, but not for military purposes; and the Dominican Republic
% uses the design shown for state and military use but \emph{not} for
% civilian use (the civil flag and ensign lack the emblem).
%
% The flag of Barbados has mirror symmetry, so the reverse is both a mirror
% image of the obverse \emph{and} congruent to it. China and the Dominican
% Republic, in contrast, look different on the reverse, so the symbol
% \vexreverseismirror\ specifies that the reverse of the flag looks like the
% mirror image of the obverse:
% \begin{center}
% \vexreverse\space\vexauthorized\space\worldflag[turn=180]{BB}
%   \quad
% \vexreverse\space\vexauthorized\space\worldflag[turn=180]{CN}
%   \quad
% \vexreverse\space\vexauthorized\space\worldflag[turn=180]{DO}
% \end{center}
% where \vexreverse{} indicates that the back side of the flag is being shown.
%
% These three flags all have different specifications for \emph{vertical}
% display: Barbados uses ``normal'' vertical display, meaning the flag pole
% is rotated 90\textdegree\ and the flag then flips down and the reverse is
% shown; China rotates the flag 270\textdegree, meaning the \emph{obverse} of
% the flag is shown in the vertical orientation. The Dominican Republic,
% in contrast, adopts a modified design for vertical banners, in this case
% with the base design displayed normally but the emblem rotated so it
% remains upright.
%
% \begin{center}
% \vexonlyvertical\space\worldflag[vertical]{BB}
% \quad\vexonlyvertical\space\worldflag[obversevertical]{CN}
% \quad\vexonlyvertical\space\worldflag[vertical]{DO}
% \end{center}
% Another example would be a listing for Paraguay, which might look something
% like this:
% \begin{center}
%   \begin{minipage}[t]{0.3\linewidth}\centering
%     \worldflag{PY} \\
%     Paraguay \vexusage{\vexnationalflagandensign} \vexnormal\ \vexreverseisdifferent\ \vexrotatevertical
%   \end{minipage}
% \quad
%   \begin{minipage}[t]{0.3\linewidth}\centering
%     \worldflag[turn=180]{PY} \\
%     Paraguay (reverse) \vexreverse\ \vexauthorized\ \vexrotatevertical
%   \end{minipage}
% \end{center}
% The symbols on the left-hand image indicate that the flag is used both as
% the national flag and the national ensign (i.e., for all uses on both land
% and sea). The \vexnormal\ symbol indicates that the flag is established by
% law and the view shown is the obverse. The symbol \vexreverseisdifferent\
% indicates that the reverse side has a different design, which is the image
% on the right-hand side. On the right side, the symbol \vexreverse\ indicates
% that the image shown is the reverse side of the flag; the symbol
% \vexauthorized\ is used here to denote that the image shows is part of the
% statutory description of the flag\footnote{The symbol \vexnormal\ implies
%   that the flag is established by law and/or officially adopted somehow,
%   so the \vexauthorized\ symbol is not needed if \vexnormal\ is present.}
%
% The symbol \vexrotatevertical\ indicates that part---but not all---of the
% design should be rotated when displaying the flag vertically. In this case,
% it dictates that the correct vertical display of Paraguay's flag is the
% image on the right, \emph{not} the image on the left:
% \begin{center}
%   \vexunauthorized\
%   \tikz{\pic [country=PY,rotate=270] {worldflag};}
%   \qquad
%   \vexonlyvertical\ \vexauthorized\
%   \worldflag[vertical]{PY}
% \end{center}
% The difference between \vexnormalvertical\ and \vexobversevertical\ is
% the difference between the two images below:
% \begin{center}
%   \vexonlyvertical\ \vexauthorized\
%   \worldflag[vertical]{US}
% \qquad
%   \vexunauthorized\
%   \worldflag[obversevertical]{US}
% \end{center}
% The \emph{correct} way to hang the flag of the USA vertically is the version
% on the left, meaning the base design would have the symbol
% \vexnormalvertical:
% \begin{center}
%   \worldflag{US} \\
%   USA \vexusage{63} \vexreverseismirror\ \vexnormalvertical
% \end{center}
% If the correct vertical version was the one on the right, the symbol
% \vexobversevertical\ would be used instead (as it is for the flag of China
% earlier in this section).
%
% \section{Symbol Size}
% The vexillogical symbols should scale properly with font size:
% \begin{quote}
%   {\tiny \command"\tiny" text N\vexusage{1} \vexnormal} \\
%   {\scriptsize \command"\scriptsize" text N\vexusage{2} \vexhistorical} \\
%   {\footnotesize \command"\footnotesize" text N\vexusage{3} \vexdefacto} \\
%   {\small \command"\small" text N\vexusage{4} \vexproposed} \\
%   {\normalsize \command"\normalsize" text N\vexusage{5} \vexalternative} \\[0.5ex]
%   {\large \command"\large" text N\vexusage{6} \vexauthorized} \\[1ex]
%   {\Large \command"\Large" text N\vexusage{7} \vexreverseismirror} \\[1.5ex]
%   {\LARGE \command"\LARGE" text N\vexusage{8} \vexreverseiscongruent} \\[1.5ex]
%   {\huge \command"\huge" text N\vexusage{9} \vexnormalvertical} \\[1.5ex]
%   {\Huge \command"\Huge" text N\vexusage{10} \vexrotatevertical}
% \end{quote}
%
% \StopEventually{\PrintChanges\PrintIndex}
%
% \iffalse
%<*package>
% \fi
%
% \section{Implementation}
% The |extended| option causes \emph{all} \command"\vexusage" commands to
% produce an ``extended'' symbol ($3 \times 3$ grid).
%    \begin{macrocode}
\newif\ifvexallextended
\DeclareOption{extended}{\vexallextendedtrue}
\ProcessOptions
%    \end{macrocode}
% This package requires \TikZ\ and its |arrows.meta| library.
%    \begin{macrocode}
\RequirePackage{tikz}
\usetikzlibrary{arrows.meta}
%    \end{macrocode}
% We scale each symbol relative to the height of the letter $x$ in the current
% font so they scale with text size. The height of the $2 \times 3$ grid is
% intended to match the height of the baseline--capline distance (the height
% of most capital letters).
%    \begin{macrocode}
\newcommand*{\vexxscale}{0.8ex}
\newcommand*{\vexyscale}{0.8ex}
%    \end{macrocode}
% The \command"\vexgrid" macro draws the ordinary $2 \times 3$ grid; the
% \command"\vexgridextended" macro draws the ``extended'' grid ($3\times 3$).
%    \begin{macrocode}
\newcommand*{\vexgrid}{%
  \draw (0,0) -- (3,0)
    (1,-1) -- (1,1)
    (2,-1) -- (2,1);
}
\newcommand*{\vexgridextended}{%
  \draw (0,0) -- (3,0)
    (0,1) -- (3,1)
    (1,-1) -- (1,2)
    (2,-1) -- (2,2);
}
%    \end{macrocode}
% These commands actually draw the dots.
%    \begin{macrocode}
\newcommand*{\vexdotone}{%
  \fill (0.5,0.5) circle (0.35);
}
\newcommand*{\vexdottwo}{%
  \fill (1.5,0.5) circle (0.35);
}
\newcommand*{\vexdotthree}{%
  \fill (2.5,0.5) circle (0.35);
}
\newcommand*{\vexdotfour}{%
  \fill (0.5,-0.5) circle (0.35);
}
\newcommand*{\vexdotfive}{%
  \fill (1.5,-0.5) circle (0.35);
}
\newcommand*{\vexdotsix}{%
  \fill (2.5,-0.5) circle (0.35);
}
\newcommand*{\vexdotseven}{%
  \fill (0.5,1.5) circle (0.35);
}
\newcommand*{\vexdoteight}{%
  \fill (1.5,1.5) circle (0.35);
}
\newcommand*{\vexdotnine}{%
  \fill (2.5,1.5) circle (0.35);
}
%    \end{macrocode}
% The \command"\vexusage" takes a whole-number argument ($0,1,\dotsc$).
% Numbers will be interpreted modulo 512 (e.g., if 513 is passed to this
% function, it will be interpreted as $513\mod{512} = 1$), which is
% accomplished by repeated integer division modulo~2.
%    \begin{macrocode}
\NewDocumentCommand{\vexusage}{s m}{%
\begin{tikzpicture}[x=\vexxscale,y=\vexyscale]
  \IfBooleanTF {#1}
    {\vexgridextended}
    {
      \ifvexallextended
        \vexgridextended
      \else
        \pgfmathparse{int(#2)}
        \ifnum\pgfmathresult>63\relax
          \vexgridextended
        \else
          \vexgrid
        \fi
      \fi
    }
  \pgfmathparse{int(mod(#2,2))}
  \ifnum\pgfmathresult=1\relax
    \vexdotone
  \fi
  \pgfmathparse{int(mod(div(#2,2),2))}
  \ifnum\pgfmathresult=1\relax
    \vexdottwo
  \fi
  \pgfmathparse{int(mod(div(#2,4),2))}
  \ifnum\pgfmathresult=1\relax
    \vexdotthree
  \fi
  \pgfmathparse{int(mod(div(#2,8),2))}
  \ifnum\pgfmathresult=1\relax
    \vexdotfour
  \fi
  \pgfmathparse{int(mod(div(#2,16),2))}
  \ifnum\pgfmathresult=1\relax
    \vexdotfive
  \fi
  \pgfmathparse{int(mod(div(#2,32),2))}
  \ifnum\pgfmathresult=1\relax
    \vexdotsix
  \fi
  \pgfmathparse{int(mod(div(#2,64),2))}
  \ifnum\pgfmathresult=1\relax
    \vexdotseven
  \fi
  \pgfmathparse{int(mod(div(#2,128),2))}
  \ifnum\pgfmathresult=1\relax
    \vexdoteight
  \fi
  \pgfmathparse{int(mod(div(#2,256),2))}
  \ifnum\pgfmathresult=1\relax
    \vexdotnine
  \fi
\end{tikzpicture}}
%    \end{macrocode}
% These user-facing macros are intended as arguments to the
% \command"\vexusage" macro. Ideally, we would bit-wise AND the argument,
% but because most of these do not share bits, it is sufficient to add them.
%    \begin{macrocode}
\newcommand*{\vexcivilflag}{1}
\newcommand*{\vexstateflag}{2}
\newcommand*{\vexwarflag}{4}
\newcommand*{\vexcivilensign}{8}
\newcommand*{\vexstateensign}{16}
\newcommand*{\vexwarensign}{32}
\newcommand*{\vexcivilairensign}{64}
\newcommand*{\vexstateairensign}{128}
\newcommand*{\vexwarairensign}{256}
\newcommand*{\vexnationalflag}{7}
\newcommand*{\vexnationalensign}{56}
\newcommand*{\vexnationalflagandensign}{63}
\newcommand*{\vexnationaleverything}{511}
%    \end{macrocode}
% These are drawn based on the images in Smith's book as well as the images
% on the Wikipedia.
%    \begin{macrocode}
\newcommand*{\vexnormal}{%
\begin{tikzpicture}[x=\vexxscale,y=\vexyscale]
  \draw (0,-0.4) -- (0,1) -- (2,1) -- (2,0) -- (0,0);
\end{tikzpicture}}
\newcommand*{\vexproposed}{%
\begin{tikzpicture}[x=\vexxscale,y=\vexyscale]
  \draw (0,-0.4) -- (0,1) -- (2,1) (2,0) -- (0,0);
\end{tikzpicture}}
\newcommand*{\vexreconstruction}{%
\begin{tikzpicture}[x=\vexxscale,y=\vexyscale]
  \draw (0,-0.4) -- (0,1) -- (2,1) -- (2,0) -- (0,0);
%  \node at (1,0.5) {\resizebox{!}{0.5ex}{?}};% FIXME?
  \fill (0.9875,0.2) circle (0.075*\vexxscale);
  \draw [line width=0.125*\vexyscale,line cap=round]
    (0.9875,0.381) .. controls +(0,0.25) and +(0,-0.12) .. (1.125,0.70)
    .. controls +(0,0.09) and +(0.05,0) .. (1,0.8125)
    .. controls +(-0.09,0) and +(0,0.065) .. (0.85,0.702);
\end{tikzpicture}}
\newcommand*{\vexreverse}{%
\begin{tikzpicture}[x=\vexxscale,y=\vexyscale]
  \draw (0,-0.4) -- (0,1) -- (2,1) -- (2,0) -- (0,0);
  \draw [-{Straight Barb[length=0.25ex,width=0.25ex]}] (1,0.5) -- (2.75,0.5);
\end{tikzpicture}}
\newcommand*{\vexvariant}{%
\begin{tikzpicture}[x=\vexxscale,y=\vexyscale]
  \draw (0,-0.4) -- (0,1) -- (2,1) -- (2,0) -- (0,0);
  \draw (-0.2,-0.5) .. controls +(-0.4,0.3) and +(-0.4,-0.3) .. (-0.2,1.1);
  \draw (2.2,-0.5) .. controls +(0.4,0.3) and +(0.4,-0.3) .. (2.2,1.1);
\end{tikzpicture}}
\newcommand*{\vexalternative}{%
\begin{tikzpicture}[x=\vexxscale,y=\vexyscale]
  %\draw[green] (0,-0.4) -- (0,1) -- (2,1) -- (2,0) -- (0,0);
  \draw (0,-0.4) -- (0,1) -- (2,1) -- (2,0.5)
    (0.5,0) -- (0,0);
  \draw [xshift=0.4ex,yshift=-0.4ex]
    (0,-0.4) -- (0,1) -- (2,1) -- (2,0) -- (0,0);
\end{tikzpicture}}
\newcommand*{\vexdefacto}{%
\begin{tikzpicture}[x=\vexxscale,y=\vexyscale]
  \draw (0,-0.4) -- (0,1) -- (2,1) -- (2,0) -- (0,0);
  \draw (0.5,-0.2) -- (1.5,1.2);
\end{tikzpicture}}
\newcommand*{\vexreverseisdifferent}{%
\begin{tikzpicture}[x=\vexxscale,y=\vexyscale,
    >={Straight Barb[length=0.25ex,width=0.25ex]}]
  \draw [->] (0,0) -- (2,0);
  \draw [->] (1.5,0.5) -- (-0.5,0.5);
  \draw (0.25,-0.5) -- (1.25,1);
\end{tikzpicture}}
\newcommand*{\vexsinisterhoist}{%
\begin{tikzpicture}[x=\vexxscale,y=\vexyscale]
  \draw (0,0) -- (0,1) -- (2,1) -- (2,-0.4) -- (2,0) -- cycle;
\end{tikzpicture}}
\newcommand*{\vexhistorical}{%
\begin{tikzpicture}[x=\vexxscale,y=\vexyscale,line cap=rect]
  \draw (0,-0.4) -- (0,1) -- (1.2,1) -- (0.6,0) -- (0,0);
  \draw (2,-0.4) -- (2,0.7) -- (1.5,0.7) -- (0.8,-0.4) -- cycle;
\end{tikzpicture}}
\newcommand*{\vexreverseismirror}{%
\begin{tikzpicture}[x=\vexxscale,y=\vexyscale,line cap=rect,
    >={Straight Barb[length=0.25ex,width=0.35ex]}]
  \draw (2,-0.5) -- (2,1) -- (0,1) -- (0,0) -- (2,0);
  \draw [->] (0.25,-0.125) .. controls +(0.25,-0.20) and +(-0.25,0) .. (1.75,-0.25);
  \draw [line cap=round] (0.75,0.15) -- ++(0.25,0.35)
    (1.25,0.15) -- (1.25,0.85)
    -- (0.85,0.85) .. controls (0.70,0.8) and (0.70,0.6) .. (0.85,0.5)
    -- (1.25,0.5);
\end{tikzpicture}}
\newcommand*{\vexreverseiscongruent}{%
\begin{tikzpicture}[x=\vexxscale,y=\vexyscale,line cap=rect,
    >={Straight Barb[length=0.25ex,width=0.35ex]}]
  \draw (2,-0.5) -- (2,1) -- (0,1) -- (0,0) -- (2,0);
  \draw [->] (0.25,-0.125) .. controls +(0.25,-0.20) and +(-0.25,0) .. (1.75,-0.25);
  \draw (1.25,0.15) -- (0.75,0.15) -- (0.75,0.85) -- (1.25,0.85)
    (0.75,0.5) -- (1.15,0.5);
\end{tikzpicture}}
\newcommand*{\vexnormalvertical}{%
\begin{tikzpicture}[x=\vexxscale,y=\vexyscale,line cap=rect]
  \draw (2.125,1.25) -- (-0.125,1.25) -- (-0.125,-0.25)
    -- (1.125,-0.25) -- (1.125,1.25);
  \begin{scope}
    \clip (0.1,0.1) rectangle (0.9,0.9);
    \draw (0.85,0.15) -- (0.15,0.15) -- (0.85,0.85) -- (0.15,0.85);
  \end{scope}
\end{tikzpicture}}
\newcommand*{\vexobversevertical}{%
\begin{tikzpicture}[x=\vexxscale,y=\vexyscale,line cap=rect]
  \draw (-0.125,1.25) -- (-0.125,-0.25)
    -- (1.125,-0.25) -- (1.125,1.25) -- (-1.125,1.25);
  \begin{scope}
    \clip (0.1,0.1) rectangle (0.9,0.9);
    \draw (0.85,0.15) -- (0.15,0.15) -- (0.85,0.85) -- (0.15,0.85);
  \end{scope}
\end{tikzpicture}}
\newcommand*{\vexrotatevertical}{%
\begin{tikzpicture}[x=\vexxscale,y=\vexyscale,line cap=rect]
  \draw (2.125,1.25) -- (-0.125,1.25) -- (-0.125,-0.25)
    -- (1.125,-0.25) -- (1.125,1.25);
  \draw [line cap=round] (0.20,0.1) -- (0.20,0.9) -- (0.75,0.9)
    .. controls (0.90,0.7625) and (0.90,0.5875) .. (0.75,0.5) -- (0.20,0.5)
    (0.55,0.5) -- (0.82,0.1);
\end{tikzpicture}}
\newcommand*{\vexunknownvertical}{%
\begin{tikzpicture}[x=\vexxscale,y=\vexyscale,line cap=rect]
  \draw (2.125,1.25) -- (-0.125,1.25) -- (-0.125,-0.25)
    -- (1.125,-0.25) -- (1.125,1.25);
%  \node at (0.5,0.5) {\resizebox{!}{0.5ex}{?}};% FIXME?
  \fill (0.49375,0.2) circle (0.075*\vexxscale);
  \draw [line width=0.125*\vexyscale,line cap=round]
    (0.49375,0.381) .. controls +(0,0.25) and +(0,-0.12) .. (0.64125,0.70)
    .. controls +(0,0.09) and +(0.05,0) .. (0.50625,0.8125)
    .. controls +(-0.09,0) and +(0,0.065) .. (0.35625,0.702);
\end{tikzpicture}}
\newcommand*{\vexnorotating}{%
\begin{tikzpicture}[x=\vexxscale,y=\vexyscale,line cap=rect]
  %\draw (2,1) -- (0,1) -- (0,0) -- (1,0) -- (1,1);
  \draw (2.125,1.25) -- (-0.125,1.25) -- (-0.125,-0.25)
    -- (1.125,-0.25) -- (1.125,1.25);
\end{tikzpicture}}
\newcommand*{\vexunauthorized}{%
\begin{tikzpicture}[x=\vexxscale,y=\vexyscale]
  \draw (0,-0.4) -- (0,1) -- (2,1) -- (2,0) -- (0,0);
  \draw (0.5,-0.2) -- (1.5,1.2);
  \draw (1.5,-0.2) -- (0.5,1.2);
\end{tikzpicture}}
\newcommand*{\vexonlyvertical}{%
\begin{tikzpicture}[x=\vexxscale,y=\vexyscale]
  \draw (0,0) rectangle (1.5,1.5);
  \draw (0.75,0) -- ++(0,-0.4);
  \draw (0.75,1.5) -- ++(0,0.2);
\end{tikzpicture}}
\newcommand*{\vexauthorized}{%
\begin{tikzpicture}[x=\vexxscale,y=\vexyscale]
  \draw (0,0) circle (0.75);
  \draw (0,0) ellipse (0.25 and 0.375);
\end{tikzpicture}}
%    \end{macrocode}
% \iffalse
%</package>
% \fi
%
% \Finale
\endinput
