% \iffalse meta-comment
%<*internal>
\iffalse
%</internal>
%<*dummy>
I'd like to keep this part here for later use.
%</dummy>
%<*internal>
\fi
\def\nameofplainTeX{plain}
\ifx\fmtname\nameofplainTeX\else
  \expandafter\begingroup
\fi
%</internal>
%<*install>
\input l3docstrip.tex
\keepsilent
\askforoverwritefalse
\preamble
Copyright (C) 2016-2026, Ruini Xue <xueruini@gmail.com>

It may be distributed and/or modified under the conditions of
the LaTeX Project Public License (LPPL), either version 1.3c of
this license or (at your option) any later version.  The latest
version of this license is in the file:

   http://www.latex-project.org/lppl.txt
\endpreamble
\postamble

This work is "maintained" (as per LPPL maintenance status) by
  Ruini Xue.

This work consists of the file  zebra.dtx
          and the derived files zebra.ins,
                                zebra.pdf,
                                zebra.sty, and
                                zebra-goodies.sty.

\endpostamble
\usedir{tex/latex/zebra}
\generate{
  \file{\jobname.sty}{\from{\jobname.dtx}{package}}
  \file{\jobname-goodies.sty}{\from{\jobname.dtx}{compat}}
}
\nopreamble\nopostamble
\generate{
  \file{\jobname-demo-twocol.tex}{\from{\jobname.dtx}{demo-twocol}}
}
%</install>
%<install>\endbatchfile
%<*internal>
\usedir{source/latex/zebra}
\generate{
  \file{\jobname.ins}{\from{\jobname.dtx}{install}}
}
%\nopreamble\nopostamble
%\usedir{doc/latex/zebra}
%\generate{
%  \file{README.md}{\from{\jobname.dtx}{dummy}}
%}
\ifx\fmtname\nameofplainTeX
  \expandafter\endbatchfile
\else
  \expandafter\endgroup
\fi
%</internal>
%<*driver|package>
%\RequirePackage{xparse}
%</driver|package>
%<*driver>
\documentclass[full]{l3doc}
\usepackage[scaled=0.93]{helvet}
\usepackage[final]{listings}
\usepackage{fontawesome}
\usepackage{graphicx}
\graphicspath{{./out/}}
\usepackage{zebra}
\zebrasetup{symbol/fixed=\manerrarrow}
\colorlet{mycyan}{cyan!80!black}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
  \DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%
%\makeatletter
%
%^^A For creating examples with nice highlighting of code, and so
%^^A on; based on the system used in the listings source (lstsample).
%\lst@RequireAspects{writefile}
%\newsavebox{\LaTeXdemo@box}
%\lstnewenvironment{LaTeXdemo}[1][code and example]{^^A
%  \global\let\lst@intname\@empty
%  \expandafter\let\expandafter\LaTeXdemo@end
%    \csname LaTeXdemo@#1@end\endcsname
%  \@nameuse{LaTeXdemo@#1}^^A
%}{^^A
%  \LaTeXdemo@end
%}
%\newcommand*\LaTeXdemo@new[3]{^^A
%  \expandafter\newcommand\expandafter*\expandafter
%    {\csname LaTeXdemo@#1\endcsname}{#2}^^A
%  \expandafter\newcommand\expandafter*\expandafter
%    {\csname LaTeXdemo@#1@end\endcsname}{#3}^^A
%}
%\newcommand*\LaTeXdemo@common{^^A
%  \setkeys{lst}{
%    basicstyle      = \small\ttfamily,
%    %basewidth      = 0.51em,
%    frame           = l,
%    backgroundcolor = \color{gray!5},
%    gobble          = 3,
%    keywordstyle    = \bfseries\color{blue},
%    language        = [LaTeX]{TeX},
%    moretexcs       = {
%      todo            ,
%      note            ,
%      comment         ,
%      fixed           ,
%      placeholder     ,
%      question        ,
%      zebratodo       ,
%      zebranote       ,
%      zebracomment    ,
%      zebrafixed      ,
%      zebraplaceholder,
%      zebranewnote    ,
%      zebraref        ,
%      zebrasetup      ,
%      colorlet
%    }
%  }^^A
%}
%\newcommand*\LaTeXdemo@input{^^A
%  \MakePercentComment
%  \small
%  \begingroup
%    \endlinechar=13\relax
%    \catcode`\^^M=5\relax
%    \input{\jobname.tmp}^^A
%  \endgroup
%  \MakePercentIgnore
%}
%\LaTeXdemo@new{code and example}{^^A
%  \setbox\LaTeXdemo@box=\hbox\bgroup
%    \lst@BeginAlsoWriteFile{\jobname.tmp}^^A
%    \LaTeXdemo@common
%}{^^A
%    \lst@EndWriteFile
%  \egroup
%  \begin{center}
%    \ifdim\wd\LaTeXdemo@box>0.48\linewidth\relax
%      \hbox to\linewidth{\box\LaTeXdemo@box\hss}^^A
%        \begin{minipage}{\linewidth}
%          \LaTeXdemo@input
%        \end{minipage}
%    \else
%      \begin{minipage}{0.48\linewidth}
%        \LaTeXdemo@input
%      \end{minipage}
%      \hfill
%      \begin{minipage}{0.48\linewidth}
%        \hbox to\linewidth{\box\LaTeXdemo@box\hss}^^A
%      \end{minipage}
%    \fi
%  \end{center}
%}
%\LaTeXdemo@new{code only}{^^A
%  \LaTeXdemo@common
%}{^^A
%}
%
%\providecommand*\opt[1]{\texttt{#1}}
%
%\makeatother
%
%\GetFileInfo{\jobname.sty}
%
%\changes{v0.1.0}{2017/07/05}{Initial public release}
%\changes{v0.2.0}{2017/11/26}{Fix \pkg{xcolor} conflict}
%\changes{v0.3.0}{2017/12/06}{Detect command conflicts}
%\changes{v0.4.0}{2019/06/29}{Show note number for easy reference}
%\changes{v0.5.0}{2019/06/29}{Use darker color for label}
%\changes{v0.6.0}{2019/06/30}{Use gray background for label}
%\changes{v0.9.0}{2026/02/25}{Fix legacy bugs and improve implementation}
%\changes{v0.9.1}{2026/02/27}{Beautify the numbers.}
%\changes{v0.9.2}{2026/03/03}{Faster.}
%\changes{v1.0.0}{2026/03/16}{\pkg{expl3}, list of notes and compatibility.}
%\changes{v1.1.0}{2026/03/21}{Customisable margin symbol, accurate page numbers, code cleanup.}
%\changes{v1.1.1}{2026/03/22}{Per-type \texttt{color}/\texttt{symbol} keys, \cs{zebrasetup}.}
%\changes{v1.2.0}{2026/03/23}{Simplify key architecture.}
%\changes{v1.3.0}{2026/03/25}{Rename package to \pkg{zebra}.}
%\changes{v1.3.0}{2026/03/25}{Rename the page-link option to \opt{pagelinks}/\opt{nopagelinks}.}
%\changes{v1.3.0}{2026/03/25}{Rename the microtype expansion option to \opt{font-expansion}.}
%\changes{v1.4.0}{2026/04/03}{Support note labels via \cs{label}, \cs{ref}, and \cs{zebraref}.}
%
%\title{^^A
%  \pkg{zebra} --- Writing Revision Toolkit^^A
%    \thanks{^^A
%      This package was previously distributed as \pkg{zebra-goodies}.
%      The old name still works but will print a deprecation warning. Please
%      update to \pkg{zebra}.^^A
%    }^^A
%}
%\author{^^A
%  Ruini Xue\thanks{xueruini@gmail.com}^^A
%}
%\date{\fileversion~(\filedate)}
%
%\maketitle
%
%\begin{abstract}
%  The \pkg{zebra} package is a writing revision toolkit. The current release
%  focuses on inline note-taking, with a lightweight set of macros designed to
%  be simple and practical for both solo and collaborative workflows. Five
%  built-in commands---\cs{todo}, \cs{note}, \cs{comment}, \cs{fixed}, and
%  \cs{placeholder}---cover common use cases out of the box, and
%  \cs{zebranewnote} lets you define additional note types as needed. Notes are
%  automatically numbered per type, marked with a customisable
%  symbol\marginnote{\textdbend} (default: \cs{textdbend}) in the nearest
%  margin, and summarised with a summary table plus a detailed note list at the
%  end of the document. Passing the \opt{final} option suppresses all notes for
%  production output.
%\end{abstract}
%
%\tableofcontents
%
%\begin{documentation}
%
%\section{Introduction}
%
% \pkg{zebra} is a writing revision toolkit. The current release focuses on
% inline note-taking. Many note-taking and to-do packages exist for \LaTeX{},
% but most fall into one of two traps: they either offer an overwhelming
% feature set that tries to cover every conceivable use case, or they clutter
% the margins with oversized colourful boxes and arrows that make the document
% hard to read.
%
% \pkg{zebra} takes a different approach. It aims to be \emph{simple}
% ---intuitive commands with only the arguments you actually need---and
% \emph{good enough}---notes appear inline with a small visual cue in the
% margin, keeping the document readable while still making annotations easy to
% spot. Each note type is automatically numbered, and a summary table plus a
% detailed note list at the end of the document serve as a gentle reminder to
% address them before the final version.
%
% The package requires \LaTeX{} 2022-06-01 or later.
%
%\section{Installation}
%
%\changes{v0.7.0}{2019/07/01}{Move to docstrip}
%
% The package is supplied in \file{dtx} format and as a pre-extracted zip file.
% The latter is the most convenient option for most users: simply unzip it into
% your local texmf directory and run \texttt{texhash} to update the file-name
% database, or unzip the files directly into your working directory. To unpack
% the \file{dtx} yourself, run \texttt{tex \jobname.dtx} to extract the package,
% or \texttt{pdflatex \jobname.dtx} to extract it and typeset the documentation at
% the same time.\footnote{Running \texttt{latexmk \jobname.dtx} is even more
% convenient as it handles multiple compilation passes automatically.}
%
%\section{Using the package}
%
% Load the package in the preamble with any desired options.
%\begin{LaTeXdemo}[code only]
%  \usepackage[<options>]{zebra}  % was zebra-goodies
%\end{LaTeXdemo}
%
%\subsection{Package Options}
%\label{sec:options}
%
%\DescribeOption{draft}
%\DescribeOption{final}
% These two options are complementary. Default: \texttt{true} (draft mode). All
% notes are typeset inline and a summary table plus a detailed note list are
% appended at the end of the document. Setting \opt{final} (or |draft=false|)
% suppresses all notes and the generated lists, producing clean output ready for
% distribution.
%
%\DescribeOption{sort}
% Controls the order of the detailed note list printed at the end of the
% document. Default: \texttt{none} (document order).
% |sort=type| groups them by note type.
%
%\DescribeOption{font-expansion}
% Controls \pkg{microtype} font expansion, which usually improves the
% appearance of the document. Disable it if it conflicts with your
% engine or another package. Default: \texttt{true}. \pkg{microtype}
% remains loaded when expansion is disabled.
%
%\DescribeOption{pagelinks}
% Controls whether page numbers in the detailed note list are clickable.
% Default: \texttt{true}. Set |pagelinks=false| or use the complementary
% option \opt{nopagelinks} to suppress them.
%
%\subsection{Notes Macros}
%
% All note commands share the syntax \cs{cmd}\oarg{name}\marg{text}. Each also
% has a prefixed alias (e.g.\ \cs{zebratodo}) that is always available,
% regardless of name conflicts. If a short name clashes with another loaded
% package, \pkg{zebra} will \emph{not} overwrite the existing
% definition; use the prefixed form instead.
%
%\begin{function}{\todo, \zebratodo}
%  \begin{syntax}
%    \cs{todo}\oarg{name}\marg{text}
%    \cs{zebratodo}\oarg{name}\marg{text}
%  \end{syntax}
%\end{function}
%
% The primary command provided by \pkg{zebra} is \cs{todo}. It inserts
% an inline note in the current paragraph, typeset in a predefined colour and
% marked with a symbol in the nearest margin. The mandatory \meta{text}
% describes the task; the optional \meta{name} specifies who is responsible for
% addressing it, which is particularly useful during collaborative writing.
%
% \begin{LaTeXdemo}
%   The motivation section still feels too vague \todo{revise the introduction
%   before submission} and could benefit from a concrete running example to
%   guide the reader through the key ideas step by step.
% \end{LaTeXdemo}
%
% The optional argument assigns one or more people to the note. Assignees appear
% prefixed with \texttt{@}, and notes of the same type are numbered
% sequentially.
%
% \begin{LaTeXdemo}
%   The related work section needs more references \todo[alice]{add two or
%   three citations from the latest survey} to recent advances in the field. We
%   should also double-check the experimental setup before the camera-ready
%   deadline \todo[bob, carol]{verify the hyperparameter table against the
%   source code and update any outdated entries and let's check afterwards}.
% \end{LaTeXdemo}

% Because notes are set as inline text, they work inside moving arguments
% such as \cs{section} and \cs{caption} without issues.
%
% \begin{LaTeXdemo}[code only]
%   \section{Introduction\todo[jerry]{please figure out a better name}}
%   \begin{figure}
%     \centering
%     \caption{Speed vs distance. \todo{need to insert the figure}}
%   \end{figure}
% \end{LaTeXdemo}
%
%\begin{function}{\note, \zebranote}
%  \begin{syntax}
%    \cs{note}\oarg{name}\marg{text}
%    \cs{zebranote}\oarg{name}\marg{text}
%  \end{syntax}
%\end{function}
%\begin{function}{\comment, \zebracomment}
%  \begin{syntax}
%    \cs{comment}\oarg{name}\marg{text}
%    \cs{zebracomment}\oarg{name}\marg{text}
%  \end{syntax}
%\end{function}
%\begin{function}{\fixed, \zebrafixed}
%  \begin{syntax}
%    \cs{fixed}\oarg{name}\marg{text}
%    \cs{zebrafixed}\oarg{name}\marg{text}
%  \end{syntax}
%\end{function}
%\begin{function}{\placeholder, \zebraplaceholder}
%  \begin{syntax}
%    \cs{placeholder}\oarg{name}\marg{text}
%    \cs{zebraplaceholder}\oarg{name}\marg{text}
%  \end{syntax}
%\end{function}
% These commands share the same syntax and behaviour as \cs{todo}; they differ
% only in name and colour, providing semantic distinction for different
% annotation purposes. Note that \cs{zebracomment} is used in the example below
% because \cs{comment} is already defined by \pkg{l3doc}.
% \begin{LaTeXdemo}
%   We may want to reorganise \note{how should we structure the intro?} this
%   part before the final submission. The experimental setup in Section~2 has
%   already been reviewed by a collaborator \zebracomment[tom]{the setup
%   description looks clear now}. Results are presented in the following tables
%   and figures, but some of them are still missing.
%
%   The discussion has been revised \placeholder[lucy, tom]{good job!}
%   and the related work comparison strengthened with two additional references.
%   The list of references still needs a second pass \todo{check bibliography
%   entries for formatting} before we can finalize the submission.
%
%   With those items addressed, the conclusion has been rewritten so the
%   argument flows more naturally from the results. \fixed[John]{updated the
%   conclusion} The overall structure now matches the revised outline we agreed
%   on last week. \note[who]{anything else?} If not, the draft should be fine.
% \end{LaTeXdemo}
%
%\begin{function}{\zebranewnote}
%  \begin{syntax}
%    \cs{zebranewnote}\marg{note name}\marg{xcolor name}\oarg{symbol}
%  \end{syntax}
%\end{function}
% Creates a new note type. The \meta{note name} becomes the command name
% (e.g.\ passing |question| creates \cs{question} and \cs{zebraquestion}), and
% \meta{xcolor name} sets its colour. The colour must be a named colour already
% known to \pkg{xcolor}; define it with \cs{definecolor} or \cs{colorlet}
% beforehand if needed. The optional \meta{symbol} overrides the default margin
% symbol (\cs{textdbend}) for this note type only. Per-type symbols can also be
% changed after loading via
% |\zebrasetup{symbol/|\meta{type}|=|\meta{symbol}|}|.
% \changes{v0.8.0}{2019/07/04}{Fix new note demo}
% \changes{v0.8.1}{2019/07/04}{Fix doc}
% \begin{LaTeXdemo}
%   \colorlet{mycyan}{cyan!80!black}
%   \zebranewnote{question}{mycyan}[\faQuestionCircle] % \usepackage{fontawesome}
%
%   When it moves to the next step, we should be fine.\question[who]{what's this?}
% \end{LaTeXdemo}
%
%\begin{function}{\zebraref}
%  \begin{syntax}
%    \cs{zebraref}\marg{label}
%  \end{syntax}
%\end{function}
%
% Labels may be placed inside note bodies with the usual \cs{label} command.
% Standard \cs{ref} returns the note number, while \cs{zebraref} prints the
% note type together with the number.
% \begin{LaTeXdemo}
%   The motivation section still feels too vague \todo{\label{zebra:intro}revise
%   the introduction before submission}.  The same issue appears again later
%   \note{see Todo~\ref{zebra:intro} (that is, \zebraref{zebra:intro}) on
%   p.~\pageref{zebra:intro}}.
% \end{LaTeXdemo}
%
% As in standard \LaTeX{}, labels inside notes are unavailable in
% \opt{final} mode because the notes themselves are suppressed.
%
%\begin{function}{\zebrasetup}
%  \begin{syntax}
%    \cs{zebrasetup}\marg{key\,=\,value list}
%  \end{syntax}
%\end{function}
% Configures note appearance after loading. Accepted keys:
% \begin{itemize}
%   \item |color/|\meta{type}|=|\meta{colour} --- override the
%     colour of a note type.
%   \item |symbol/|\meta{type}|=|\meta{symbol} --- override the
%     margin symbol of a note type.
% \end{itemize}
% For example:
% \begin{LaTeXdemo}[code only]
%   \zebrasetup{symbol/fixed=\manerrarrow} % like this doc
%   \zebrasetup{color/todo=red}
% \end{LaTeXdemo}
%
%\subsection{Two-column Support}
%
% In \texttt{twocolumn} documents, the margin symbol is automatically placed on
% the nearest margin: left margin for the left column, right margin for the
% right column. No special configuration is needed. This also works correctly in
% combination with the \texttt{twoside} option.
% \lstinputlisting[
%   basicstyle=\small\ttfamily,
%   frame=l,
%   backgroundcolor=\color{gray!5},
%   firstline=3, ^^A docstrip adds 2 more lines
%   keywordstyle=\bfseries\color{blue},
%   language={[LaTeX]TeX},
%   moretexcs={todo,note,comment,fixed,placeholder,zebrasetup},
% ]{\jobname-demo-twocol.tex}
%
% The code above produces the following output:
%
% \begin{center}
%   \fbox{\includegraphics[width=\linewidth,page=1]{zebra-demo-twocol}}
% \end{center}
%
%
%
%\end{documentation}
%
%\begin{implementation}
%
%\section{Implementation}
%
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
%
%    \begin{macrocode}
%<@@=zebra>
%    \end{macrocode}
%
% Version data to start with.
%    \begin{macrocode}
\ProvidesExplPackage{zebra}
  {2026/04/03}
  {1.4.0}
  {Writing Revision Toolkit}
%    \end{macrocode}
%
%\subsection{Package options}
%
% Package options \opt{draft}, \opt{font-expansion}, \opt{pagelinks},
% and \opt{sort} are created using
% the kernel key--value interface available since \LaTeX{} 2022-06-01.
% Post-load configuration (\cs{zebrasetup}) uses a separate
% \texttt{zebra-setup} key family with \texttt{color/\meta{type}} and
% \texttt{symbol/\meta{type}} sub-families.
%    \begin{macrocode}
\bool_new:N \l@@_draft_bool
\bool_new:N \l@@_microtype_expansion_bool
\bool_new:N \l@@_pagelinks_bool
\bool_new:N \l@@_sort_none_bool
\seq_new:N \g@@_note_types_seq
\prop_new:N \g@@_note_colors_prop
\prop_new:N \g@@_note_public_alias_prop
\int_new:N \g@@_note_id_int
\tl_new:N \l@@_note_target_tl
\tl_new:N \l@@_note_color_tl
\tl_new:N \l@@_note_ref_type_tl
\tl_new:N \l@@_summary_rows_tl
\int_new:N \l@@_total_notes_int
\prop_new:N \g@@_note_symbols_prop
\tl_new:N \l@@_symbol_tl
\tl_set:Nn \l@@_symbol_tl { \textdbend }

\msg_new:nnn { zebra } { command-taken }
  {
    The~command~'\iow_char:N\\#1'~is~already~defined.~
    Use~'\iow_char:N\\zebra#1'~instead.
  }
\msg_new:nnn { zebra } { invalid-note-label }
  { Label~'#1'~is~not~a~zebra~note~label. }

\prg_new_conditional:Npnn \@@_if_package_loaded:n #1 { T , F , TF }
  {
    \cs_if_exist:cTF { ver@#1.sty }
      { \prg_return_true: }
      { \prg_return_false: }
  }

\keys_define:nn { zebra }
  {
    draft .bool_set:N = \l@@_draft_bool,
    draft .initial:n = true,
    final .meta:n = { draft = false },
    font-expansion .bool_set:N = \l@@_microtype_expansion_bool,
    font-expansion .initial:n = true,
    nofont-expansion .meta:n = { font-expansion = false },
    pagelinks .bool_set:N = \l@@_pagelinks_bool,
    pagelinks .initial:n = true,
    nopagelinks .meta:n = { pagelinks = false },
    sort .choice:,
    sort / type .code:n = { \bool_set_false:N \l@@_sort_none_bool },
    sort / none .code:n = { \bool_set_true:N \l@@_sort_none_bool },
    sort .initial:n = none,
  }
\ProcessKeyOptions [ zebra ]
\keys_define:nn { zebra-setup / color }
  {
    unknown .code:n =
      { \prop_gput:NVn \g@@_note_colors_prop \l_keys_key_str {#1} }
  }
\keys_define:nn { zebra-setup / symbol }
  {
    unknown .code:n =
      { \prop_gput:NVn \g@@_note_symbols_prop \l_keys_key_str {#1} }
  }
\sys_if_engine_xetex:T
  { \bool_set_false:N \l@@_microtype_expansion_bool }

\cs_new_protected:Npn \@@_setup_microtype:
  {
    \@@_if_package_loaded:nTF { microtype }
      {
        \bool_if:NF \l@@_microtype_expansion_bool
          { \microtypesetup { expansion = false } }
      }
      {
        \bool_if:NTF \l@@_microtype_expansion_bool
          { \RequirePackage{microtype} }
          { \RequirePackage[expansion=false]{microtype} }
      }
  }
\@@_setup_microtype:
\@@_if_package_loaded:nF { hyperref }
  {
    \bool_if:NT \l@@_pagelinks_bool
      {
        \RequirePackage{hyperref}
        \hypersetup { pdfborder = { 0~0~0 } }
      }
  }
\RequirePackage{xcolor}
\RequirePackage{marginnote}
\cs_new_eq:NN \@@_kernel_label:n \label
\cs_if_exist:NTF \dbend
  {
    \cs_set_eq:NN \@@_saved_dbend: \dbend
    \cs_undefine:N \dbend
    \RequirePackage{manfnt}
    \cs_set_eq:NN \dbend \@@_saved_dbend:
  }
  { \RequirePackage{manfnt} }
\cs_new_protected:Npn \@@_pdfstring_note:
  { \@ifnextchar [ { \@@_pdfstring_note_opt:w } { \use_none:n } }
\cs_new_protected:Npn \@@_pdfstring_note_opt:w [#1] #2 { }
\cs_new:Npn \@@_target:nn #1#2 {#2}
\cs_new:Npn \@@_link:nn #1#2 {#2}
\cs_new:Npn \@@_pageref:n #1 { \pageref {#1} }
\cs_new:Npn \@@_zebra_label_name:n #1 { #1@zebra }
\cs_new:Npn \@@_zebra_label_type:n #1
  {
    \exp_after:wN \use_i:nn
      \cs:w r@\@@_zebra_label_name:n {#1}\cs_end:
      { }
  }
\cs_new_protected:Npn \@@_write_zebra_label:n #1
  {
    \protected@write \@auxout { }
      {
        \string\newlabel{\@@_zebra_label_name:n {#1}}
          {{\exp_not:V \l@@_note_ref_type_tl}{}}
      }
  }
\cs_new_protected:Npn \@@_note_label:n #1
  {
    \@@_kernel_label:n {#1}
    \@@_write_zebra_label:n {#1}
  }
\cs_new_protected:Npn \@@_zebra_ref:n #1
  {
    \cs_if_exist:cTF { r@\@@_zebra_label_name:n {#1} }
      { \@@_zebra_label_type:n {#1}~\ref{#1} }
      {
        \msg_warning:nnn { zebra } { invalid-note-label } {#1}
        ??
      }
  }
\NewDocumentCommand \zebraref { m }
  { \@@_zebra_ref:n {#1} }
\cs_new_protected:Npn \@@_apply_pdfstring_defs:
  {
    \pdfstringdefDisableCommands
      {
        \cs_set:Npn \zebraref ##1 { \ref{##1} }
        \seq_map_inline:Nn \g@@_note_types_seq
          {
            \cs_set_eq:cN { zebra##1 } \@@_pdfstring_note:
            \prop_if_in:NnT \g@@_note_public_alias_prop { ##1 }
              { \cs_set_eq:cN { ##1 } \@@_pdfstring_note: }
          }
      }
  }
\cs_new_protected:Npn \@@_setup_pagelinks:
  {
    \cs_set:Npn \@@_target:nn ##1##2 {##2}
    \cs_set:Npn \@@_link:nn ##1##2 {##2}
    \cs_set:Npn \@@_pageref:n ##1 { \pageref {##1} }
    \@@_if_package_loaded:nT { hyperref }
      {
        \cs_set:Npn \@@_pageref:n ##1 { \pageref* {##1} }
        \bool_if:NT \l@@_pagelinks_bool
          {
            \cs_set:Npn \@@_target:nn ##1##2 { \hypertarget{##1}{##2} }
            \cs_set:Npn \@@_link:nn ##1##2 { \hyperlink{##1}{##2} }
          }
        \@@_apply_pdfstring_defs:
      }
  }
\hook_gput_code:nnn { begindocument } { zebra }
  { \@@_setup_pagelinks: }
%    \end{macrocode}
%
% \subsection{Main notes macros}
% Various helper macros are defined before reaching out to
% the \cs{todo} commands.
%
% Place the margin note on the nearest margin. Takes two arguments:
% |#1| for the left margin (number then symbol) and |#2| for the right
% margin (symbol then number), so the symbol always sits closest to the
% text column. In twocolumn mode, \cs{marginpar}'s optional argument
% selects the left-margin variant automatically. In single-column mode,
% \cs{marginnote} is used with the right-margin variant as default.
%    \begin{macrocode}
\cs_new_protected:Npn \@@_margin_note:nn #1#2
  {
    \legacy_if:nTF { @twocolumn }
      {
        \mode_if_inner:TF
          { \marginnote{#2} }
          {
            \marginpar
              [ { \makebox[\marginparwidth]{#1} } ]
              { \makebox[\marginparwidth]{#2} }
          }
      }
      { \marginnote[#1]{#2} }
  }
\cs_new:Npn \@@_prepend:nn #1#2
  { \tl_if_blank:nTF {#2} {} {#1#2} }
\cs_new:Npn \@@_capitalize_type:n #1
  { \text_uppercase:n { \tl_head:n {#1} } \tl_tail:n {#1} }
\cs_new:Npn \@@_note_count:n #1
  { \int_use:c { g@@_note_count_#1_int } }
\cs_new:Npn \@@_note_color:n #1
  { \prop_item:Nn \g@@_note_colors_prop {#1} }
\cs_new:Npn \@@_note_symbol:n #1
  {
    \prop_if_in:NnTF \g@@_note_symbols_prop {#1}
      { \prop_item:Nn \g@@_note_symbols_prop {#1} }
      { \l@@_symbol_tl }
  }
\cs_new_protected:Npn \@@_new_listbody:n #1
  { \tl_new:c { g@@_listbody_#1_tl } }
\tl_new:N \g@@_listbody_all_tl
\cs_new:Npn \@@_use_listbody:n #1
  { \tl_use:c { g@@_listbody_#1_tl } }
\cs_new_protected:Npn \@@_record_note:nnnnn #1#2#3#4#5
  {
    \tl_gput_right:cx
      {
        \bool_if:NTF \l@@_sort_none_bool
          { g@@_listbody_all_tl }
          { g@@_listbody_#1_tl }
      }
      {
        \exp_not:N \@@_list_entry:nnnnn
        { \exp_not:n {#1} }
        {#2}
        { \exp_not:n {#3} }
        { \exp_not:n {#4} }
        {#5}
      }
  }
\cs_new_protected:Npn \@@_note:nnn #1#2#3
  {
    \bool_if:NT \l@@_draft_bool
      {
      \tl_set:Nx \l@@_note_color_tl { \@@_note_color:n {#1} }
      \int_gincr:c { g@@_note_count_#1_int }
      \int_gincr:N \g@@_note_id_int
      \tl_set:Nx \l@@_note_target_tl
        { zebranote.\int_use:N \g@@_note_id_int }
      \@@_record_note:nnnnn
        {#1}
        { \@@_note_count:n {#1} }
        {#2}
        {#3}
        { \l@@_note_target_tl }
      \group_begin:
        \protected@edef \@currentlabel { \@@_note_count:n {#1} }
        \@@_if_package_loaded:nT { hyperref }
          { \tl_set:Nx \@currentHref { \l@@_note_target_tl } }
        \tl_set:Nx \l@@_note_ref_type_tl { \@@_capitalize_type:n {#1} }
        \@@_target:nn { \l@@_note_target_tl } {}
        \exp_args:NV \@@_kernel_label:n \l@@_note_target_tl
        \@@_margin_note:nn
          {\textcolor{\l@@_note_color_tl}{%
            {\bfseries\@@_note_count:n {#1}}\kern1pt\@@_note_symbol:n {#1}}}
          {\textcolor{\l@@_note_color_tl}{%
            \@@_note_symbol:n {#1}\kern1pt{\bfseries\@@_note_count:n {#1}}}}%
        \cs_set_eq:NN \label \@@_note_label:n
        \textcolor{\l@@_note_color_tl}{[\colorbox[gray]{0.97}{%
            \textcolor{\l@@_note_color_tl !70!black}{%
              \textsc{\MakeLowercase{\MakeUppercase#1}}~%
              \@@_note_count:n {#1}\texttt{\@@_prepend:nn {@}{#2}}:}} #3]}%
      \group_end:
      }
  }
\cs_new_protected:Npn \@@_new_note_type:nn #1#2
  { \@@_new_note_type:nnn {#1} {#2} {} }
\cs_new_protected:Npn \@@_new_note_type:nnn #1#2#3
  {
    \seq_gput_right:Nn \g@@_note_types_seq {#1}
    \prop_if_in:NnF \g@@_note_colors_prop {#1}
      { \prop_gput:Nnn \g@@_note_colors_prop {#1} {#2} }
    \tl_if_blank:nF {#3}
      {
        \prop_if_in:NnF \g@@_note_symbols_prop {#1}
          { \prop_gput:Nnn \g@@_note_symbols_prop {#1} {#3} }
      }
    \int_new:c { g@@_note_count_#1_int }
    \@@_new_listbody:n {#1}
    \exp_args:Nc \NewDocumentCommand { zebra#1 } { O{} m }
      { \@@_note:nnn {#1}{##1}{##2} }
    \@@_if_package_loaded:nT { hyperref }
      { \@@_apply_pdfstring_defs: }
    \cs_if_exist:cTF {#1}
      { \msg_warning:nnn { zebra } { command-taken } {#1} }
      {
        \cs_set_eq:cc {#1} {zebra#1}
        \prop_gput:Nnn \g@@_note_public_alias_prop {#1} { true }
      }
  }
\cs_new_protected:Npn \@@_list_entry:nnnnn #1#2#3#4#5
  {
    \par\noindent
    \textcolor{\@@_note_color:n {#1}}{%
      \textbf{\@@_capitalize_type:n {#1}~#2}%
      \tl_if_blank:nF {#3} { \enspace \texttt{\@@_prepend:nn {@}{#3}} }}%
    \nobreak\dotfill
    \@@_link:nn {#5} { \@@_pageref:n {#5} }%
    \par
    \begingroup
      \leftskip=2em
      \rightskip=2em
      \parindent=0pt
      \cs_set_eq:NN \label \use_none:n
      #4\par
    \endgroup
  }
\cs_new_protected:Npn \@@_print_note_group:n #1
  {
    \int_compare:nNnT { \@@_note_count:n {#1} } > { 0 }
      {
        \par\medskip
        \@@_use_listbody:n {#1}
      }
  }
\cs_new_protected:Npn \@@_print_notes_inorder:
  {
    \tl_if_empty:NF \g@@_listbody_all_tl
      { \par\medskip \tl_use:N \g@@_listbody_all_tl }
  }
\cs_new_protected:Npn \@@_summary_row:n #1
  {
    \int_compare:nNnT { \@@_note_count:n {#1} } > { 0 }
      {
        \int_add:Nn \l@@_total_notes_int { \@@_note_count:n {#1} }
        \tl_put_right:Nx \l@@_summary_rows_tl
          {
            \exp_not:N \textcolor
              { \@@_note_color:n {#1} }
              {#1}
            \exp_not:N &
            \@@_note_count:n {#1}
            \exp_not:N \\
          }
      }
  }
\cs_new_protected:Npn \@@_print_notes:
  {
    \tl_clear:N \l@@_summary_rows_tl
    \int_zero:N \l@@_total_notes_int
    \seq_map_inline:Nn \g@@_note_types_seq
      { \@@_summary_row:n {##1} }
    \tl_if_empty:NF \l@@_summary_rows_tl
      {
        \par\nobreak
        \noindent\dotfill\par\medskip
        \nobreak
        \noindent\textbf{\Large Zebra~Notes}
        \par \medskip
        \begin{center}
          \begin{tabular}{lr}
            \hline
            \textbf{Type} & \textbf{Number} \\\hline
            \tl_use:N \l@@_summary_rows_tl
            \hline
            \textbf{Total} & \textbf{\int_use:N \l@@_total_notes_int} \\
            \hline
          \end{tabular}
        \end{center}
        \legacy_if:nTF { @twocolumn }
          {
            \clearpage
            \onecolumn
          }
          { \par \medskip }
        \begingroup
          \small
          \noindent{\bfseries List~of~notes}\par
          \nobreak
          \bool_if:NTF \l@@_sort_none_bool
            { \@@_print_notes_inorder: }
            {
              \seq_map_inline:Nn \g@@_note_types_seq
                { \@@_print_note_group:n {##1} }
            }
        \endgroup
      }
  }
%    \end{macrocode}
%
% \begin{macro}{\zebranewnote}
% All note types are created with \cs{zebranewnote}.
% \changes{v0.8.0}{2019/07/04}{Fix on \cs{global} for examples}
%    \begin{macrocode}
\NewDocumentCommand \zebranewnote { m m O{} }
  { \@@_new_note_type:nnn {#1} {#2} {#3} }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\zebrasetup}
% Applies configuration keys after loading using the
% \texttt{zebra-setup} key family.
%    \begin{macrocode}
\NewDocumentCommand \zebrasetup { m }
  { \keys_set:nn { zebra-setup } {#1} }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\todo}
% \begin{macro}{\note}
% \begin{macro}{\fixed}
% \begin{macro}{\comment}
% \begin{macro}{\placeholder}
% Built-in note types, defined with \cs{zebranewnote}.
%    \begin{macrocode}
\zebranewnote{todo}{purple}
\colorlet{zebra@fixed@color}{green!50!black}
\zebranewnote{fixed}{zebra@fixed@color}
\zebranewnote{comment}{blue}
\zebranewnote{note}{violet}
\zebranewnote{placeholder}{gray}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
%\subsection{Print summary at end of the document}
%
% A summary table and a detailed note list are inserted automatically at the
% end of the document. Each note type with at least one instance is listed with
% its colour and count, followed by notes in document order or grouped by type.
%
%    \begin{macrocode}
\hook_gput_code:nnn { enddocument } { zebra }
  {
    \bool_if:NT \l@@_draft_bool
      { \@@_print_notes: }
  }
\ExplSyntaxOff
%    \end{macrocode}
%    \begin{macrocode}
%</package>
%    \end{macrocode}
%
%\subsection{Compatibility shim}
%
% The old package name \pkg{zebra-goodies} is supported via a thin
% wrapper that loads \pkg{zebra} and prints a deprecation warning.
%    \begin{macrocode}
%<*compat>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{zebra-goodies}
  [2026/04/03 v1.4.0 Deprecated: use zebra instead]
\PackageWarningNoLine{zebra-goodies}
  {Package 'zebra-goodies' is deprecated.\MessageBreak
   Use \string\usepackage{zebra} instead}
\RequirePackageWithOptions{zebra}
%</compat>
%    \end{macrocode}
%
%\subsection{Two-column demo}
%
% A standalone two-column document used to generate the demo figure
% included in the documentation. It is extracted automatically by
% docstrip and compiled during the build.
%    \begin{macrocode}
%<*demo-twocol>
\documentclass[twocolumn,a4paper]{article}
\usepackage[margin=2cm]{geometry}
\usepackage{zebra}
\zebrasetup{symbol/comment=$\clubsuit$}
\usepackage{lipsum}
\pagestyle{empty}
\begin{document}
\section{Demo name\comment{revise the name}}
\lipsum[1][2-] \todo[alice]{\label{zebra:intro}revise the introduction}

\lipsum[2] \note[bob]{add a reference here}

\lipsum[3] \fixed[carol]{looks good now}

\noindent The issue raised in Todo~\ref{zebra:intro} still applies here.

\lipsum[4] \todo[dave]{needs more data}

\lipsum[5] \placeholder[eve]{insert figure}

\lipsum[6] \note[frank]{check the numbers}

\lipsum[7] \comment[tom]{is it you, jerry?}

\lipsum[8] \fixed[heidi]{typo corrected}

You can place \todo[judy]{summarise the findings} anywhere.
\lipsum[9][10-11]
\end{document}
%</demo-twocol>
%    \end{macrocode}
%
%\end{implementation}
%
%\PrintChanges
%\PrintIndex
