% \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-goodies.dtx
          and the derived files zebra-goodies.ins,
                                zebra-goodies.pdf and
                                zebra-goodies.sty.

\endpostamble
\usedir{tex/latex/zebra-goodies}
\generate{
  \file{\jobname.sty}{\from{\jobname.dtx}{package}}
}
\nopreamble\nopostamble
\generate{
  \file{\jobname-demo-twocol.tex}{\from{\jobname.dtx}{demo-twocol}}
}
%</install>
%<install>\endbatchfile
%<*internal>
\usedir{source/latex/zebra-goodies}
\generate{
  \file{\jobname.ins}{\from{\jobname.dtx}{install}}
}
%\nopreamble\nopostamble
%\usedir{doc/latex/zebra-goodies}
%\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{graphicx}
\graphicspath{{./out/}}
\usepackage{zebra-goodies}
\colorlet{mycyan}{cyan}
\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    ,
%      colorlet
%    }
%  }^^A
%}
%\newcommand*\LaTeXdemo@input{^^A
%  \MakePercentComment
%  \catcode`\^^M=10\relax
%  \small
%  \begingroup
%    \setkeys{lst}{
%      SelectCharTable=\lst@ReplaceInput{\^\^I}{\lst@ProcessTabulator}
%    }^^A
%    \leavevmode
%      \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 margin placement, drop tikz, fix counter in moving args, modernize to kernel key-value and NewDocumentCommand}
%\changes{v0.9.1}{2026/02/27}{Beautify the numbers.}
%
%\title{^^A
%  \pkg{zebra-goodies} --- Easy Notes Taking^^A
%    \thanks{^^A
%      This file describes version \fileversion, last revised
%      \filedate.^^A
%    }^^A
%}
%\author{^^A
%  Ruini Xue\thanks{E-mail: xueruini@gmail.com}^^A
%}
%\date{Released \filedate}
%
%\maketitle
%
%\begin{abstract}
%  The \pkg{zebra-goodies} package provides a lightweight set of macros for
%  inline note-taking during document writing. It is designed to be simple and
%  practical for both solo and collaborative workflows.
%  Five built-in commands---\cs{todo}, \cs{comment}, \cs{note}, \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 \cs{dbend} symbol
%  in the nearest margin, and summarised in a table at the end of the document.
%  Passing the \opt{final} option suppresses all notes for production output.
%\end{abstract}
%
%\tableofcontents
%
%\begin{documentation}
%
%\section{Introduction}
%
% 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-goodies} 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 at the
% end of the document lists how many notes of each type remain, serving 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{latex \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.
% Options are described in Section~\ref{sec:options}.
%\begin{LaTeXdemo}[code only]
%  \usepackage[<options>]{zebra-goodies}
%\end{LaTeXdemo}
%
%\subsection{Notes Macros}
%\begin{function}{\todo}
%  \begin{syntax}
%    \cs{todo}\oarg{name}\marg{note content}
%  \end{syntax}
%\end{function}
%
%  The primary command provided by \pkg{zebra-goodies} is \cs{todo}. It inserts
%  an inline note in the current paragraph, typeset in a predefined colour and
%  marked with a \cs{dbend} symbol in the nearest margin. The mandatory
%  \meta{note content} describes the task; the optional \meta{name} specifies
%  who is responsible for addressing it, which is particularly useful during
%  collaborative writing.
%
% \begin{LaTeXdemo}
%   A very simple example of a todo note \todo{how should we go to the lake?},
%   and the result will be presented right below the code snippet. Please
%   compare the code and the result.
% \end{LaTeXdemo}
%
% The following example shows how to assign notes to specific people.
% Notes of the same type are numbered sequentially, and assignees are
% prefixed with \texttt{@}.
%
% \begin{LaTeXdemo}
%   Another one with an assignee is like \todo[tom]{you should buy the ticket},
%   and you will find the same type of notes are numbered. And the assignees are
%   being \texttt{@}-ed right before the text. And another one with many
%   assignees \todo[lucy,jessie]{prepare the foo}.
% \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}
%  \begin{syntax}
%    \cs{note}\oarg{name}\marg{note text}
%  \end{syntax}
%\end{function}
%\begin{function}{\comment}
%  \begin{syntax}
%    \cs{comment}\oarg{name}\marg{comment text}
%  \end{syntax}
%\end{function}
%\begin{function}{\fixed}
%  \begin{syntax}
%    \cs{fixed}\oarg{name}\marg{fixed text}
%  \end{syntax}
%\end{function}
%\begin{function}{\placeholder}
%  \begin{syntax}
%    \cs{placeholder}\oarg{name}\marg{placeholder 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.
%
%  If any of these short names conflicts with another loaded package,
%  \pkg{zebra-goodies} will \emph{not} overwrite the existing definition.
%  Instead, it issues a warning and you should use the prefixed form
%  (e.g.\ \cs{zebracomment} instead of \cs{comment}).
%  The following example mixes several note types. Note that
%  \cs{zebracomment} is used here because \cs{comment} is already defined
%  by \pkg{l3doc}.
%  \begin{LaTeXdemo}
%    A \note{how should we go to the lake?} and a
%    \zebracomment[tom]{you should buy the ticket}. Multiple assignees
%    work too: \placeholder[lucy,jessie]{prepare the foo}. Mark resolved items
%    with \fixed[John]{good job!}. Notes of different types are numbered
%    independently: \todo{a new todo} and (let's add more words to make the next
%    note in a new line otherwise the symbols will overlap) \note[who]{another note}.
%  \end{LaTeXdemo}
%
%\begin{function}{\zebratodo}
%  \begin{syntax}
%    \cs{zebratodo}\oarg{name}\marg{note text}
%  \end{syntax}
%
%  Each built-in note command has a prefixed alias that is always available,
%  regardless of name conflicts. If \cs{todo} is already taken by another
%  package, use \cs{zebratodo} instead. The same applies to all other types.
%\end{function}
%\begin{function}{\zebranote}
%  \begin{syntax}
%    \cs{zebranote}\oarg{name}\marg{note text}
%  \end{syntax}
%\end{function}
%\begin{function}{\zebracomment}
%  \begin{syntax}
%    \cs{zebracomment}\oarg{name}\marg{comment text}
%  \end{syntax}
%\end{function}
%\begin{function}{\zebrafixed}
%  \begin{syntax}
%    \cs{zebrafixed}\oarg{name}\marg{fixed text}
%  \end{syntax}
%\end{function}
%\begin{function}{\zebraplaceholder}
%  \begin{syntax}
%    \cs{zebraplaceholder}\oarg{name}\marg{placeholder text}
%  \end{syntax}
%\end{function}
%
%\begin{function}{\zebranewnote}
%  \begin{syntax}
%    \cs{zebranewnote}\marg{note name}\marg{xcolor name}
%  \end{syntax}
%  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.
%  \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}
%    \zebranewnote{question}{mycyan}
%    When it moves to the next step, we should be fine. \question[who]{what's this?}
%  \end{LaTeXdemo}
%\end{function}
%
%\subsection{Two-column Support}
%
% In \texttt{twocolumn} documents, the \cs{dbend} 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.
% The following standalone example is extracted from this \file{dtx} file
% and compiled automatically during the build.
%
% \lstinputlisting[
%   basicstyle=\small\ttfamily,
%   frame=l,
%   backgroundcolor=\color{gray!5},
%   keywordstyle=\bfseries\color{blue},
%   language={[LaTeX]TeX},
%   moretexcs={todo,note,comment,fixed,placeholder,lipsum},
% ]{\jobname-demo-twocol.tex}
%
% The rendered result:
%
% \begin{center}
%   \fbox{\includegraphics[width=0.85\linewidth,page=1]{zebra-goodies-demo-twocol}}
% \end{center}
%
% This also works correctly in combination with the \texttt{twoside} option.
%
%\subsection{Package Options}
%\label{sec:options}
%
%\DescribeOption{draft}
%\DescribeOption{final}

% These two options are complementary. By default \opt{draft} is active:
% all notes are typeset inline and a summary table is appended at the end of
% the document. Setting \opt{final} (or |draft=false|) suppresses all notes
% and the summary table, producing clean output ready for distribution.
%
%\DescribeOption{microtype}
% Controls whether the \pkg{microtype} package is loaded. Default:
% \texttt{true}.
%
%\section{Predefined Colours}
%
% The package also defines a small palette of named colours intended for use
% with \pkg{pgfplots} or other drawing packages:
% \begin{itemize}
% \item \texttt{zebrablue}
% \item \texttt{zebrared}
% \item \texttt{zebrayellow}
% \item \texttt{zebrapurple}
% \item \texttt{zebragreen}
% \end{itemize}
%
%\end{documentation}
%
%\begin{implementation}
%
%\section{Implementation}
%
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
%
%    \begin{macrocode}
%<@@=zebra_goodies>
%    \end{macrocode}
%
% Version data to start with.
%    \begin{macrocode}
\ProvidesPackage{zebra-goodies}
[2026/02/27 0.9.1 Easy Notes Taking]
%    \end{macrocode}
%
%\subsection{Package options}
%
% Two package options \opt{draft} and \opt{microtype} are created using
% the kernel key--value interface available since \LaTeX{} 2022-06-01.
%    \begin{macrocode}
\DeclareKeys[zebra]{
  draft .if        = zebr@draft,
  draft .default:n = true,
  final .code      = \zebr@draftfalse,
  microtype .if        = zebr@microtype,
  microtype .default:n = true,
}
\SetKeys[zebra]{draft, microtype}
\ProcessKeyOptions[zebra]
\ifzebr@microtype
  \RequirePackage{microtype}
\fi
\RequirePackage{xcolor}
\RequirePackage{marginnote}
\@ifundefined{dbend}{\RequirePackage{manfnt}}{}
%    \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}
\newcommand*{\zebr@marginnote}[2]{%
  \if@twocolumn
    \ifinner
      \marginnote{#2}%
    \else
      \marginpar[{\makebox[\marginparwidth]{#1}}]{\makebox[\marginparwidth]{#2}}%
    \fi
  \else
    \marginnote{#1}%
  \fi
}
%    \end{macrocode}
%
% Then, two meta macros are used to create new types of note.
%    \begin{macrocode}
\def\zebr@note{%
  \ifzebr@draft\expandafter\zebr@note@\else\expandafter\@gobblefour\fi}
%    \end{macrocode}
%
% \cs{zebr@note@} is the core macro to typeset the note. The syntax is:
% \begin{syntax}
%    \cs{zebr@note@}\marg{note name}\marg{color}\marg{assignee}\marg{note text}
% \end{syntax}
%    \begin{macrocode}
\DeclareRobustCommand{\zebr@note@}[4]{%
  \expandafter\stepcounter{zebr@num@#1}%
  \zebr@marginnote
    {\textcolor{#2}{%
      {\bfseries\expandafter\csname thezebr@num@#1\endcsname}\kern1pt\dbend}}
    {\textcolor{#2}{%
      \dbend\kern1pt{\bfseries\expandafter\csname thezebr@num@#1\endcsname}}}%
  \textcolor{#2}{[\colorbox[gray]{0.97}{%
      \textcolor{#2!70!black}{%
        \textsc{\MakeLowercase{\MakeUppercase#1}}
        {\expandafter\csname thezebr@num@#1\endcsname}\texttt{#3}:}} #4]}}
\newcommand{\zebr@prepend}[2]{%
  \ifx\relax#2\relax\relax\else#1#2\fi}
%    \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}
\def\zebr@noteslist{}
\def\zebranewnote#1#2{%
  \g@addto@macro\zebr@noteslist{,#1}%
  \expandafter\newcounter\expandafter{zebr@num@#1}
  \expandafter\gdef\csname zebr@color@#1\endcsname{#2}
  \expandafter\NewDocumentCommand\csname zebra#1\endcsname{O{}m}{%
    \zebr@note{#1}{#2}{\zebr@prepend{@}{##1}}{##2}}
  \@ifundefined{#1}{%
    \expandafter\def\csname #1\endcsname{\csname zebra#1\endcsname}}{%
    \PackageWarning{zebra}{'\textbackslash{#1}' has been taken.
      Use '\textbackslash{zebra#1}' instead.}}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\todo}
% \begin{macro}{\note}
% \begin{macro}{\fixed}
% \begin{macro}{\comment}
% \begin{macro}{\placeholder}
% They are defined with \cs{zebranewnote}. The colors are picked up from the default
% ones from \pkg{xcolor}.
%    \begin{macrocode}
\zebranewnote{todo}{purple}
\zebranewnote{fixed}{teal}
\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 is inserted automatically at the end of the document.
% Each note type with at least one instance is listed with its colour and count.
%
%    \begin{macrocode}
\def\zebr@listnotes{%
  \ifzebr@draft\zebr@listnotes@\fi}
\def\zebr@listnotes@{%
  \def\zebr@tbl@body{}
  \edef\zebr@tbl@list{\expandafter\@gobble\zebr@noteslist}
  \@for\zebr@tbl@type:=\zebr@tbl@list\do{%
    \expandafter\ifnum\expandafter\value\expandafter{zebr@num@\zebr@tbl@type} > 0%
      \def\zebr@tbl@cnt{\expandafter\csname thezebr@num@\zebr@tbl@type\endcsname}
      \edef\zebr@tbl@row{\noexpand\textcolor{%
          \expandafter\csname zebr@color@\zebr@tbl@type\endcsname}{\zebr@tbl@type}%
        \noexpand &  \zebr@tbl@cnt\noexpand\\}
      \expandafter\g@addto@macro\expandafter\zebr@tbl@body\expandafter{\zebr@tbl@row}%
    \fi}
  \ifx\zebr@tbl@body\@empty\else%
    \noindent\dotfill\par
    \section*{Zebra Notes}
    \par \medskip
    \begin{center}
      \begin{tabular}{lr}
        \hline
        \textbf{Type} & \textbf{Number} \\\hline
        \zebr@tbl@body
        \hline
      \end{tabular}
    \end{center}
  \fi}
\AtEndDocument{\zebr@listnotes}
%    \end{macrocode}
%
%\subsection{Personal Colors}
%\label{sec:colors}
% Several colors are defined for plots.
%    \begin{macrocode}
\definecolor{zebrablue}{HTML}{4F81BD}
\definecolor{zebrared}{HTML}{C0504D}
\definecolor{zebragreen}{HTML}{9BBB00}
\definecolor{zebrapurple}{HTML}{9F4C7C}
\definecolor{zebrayellow}{HTML}{D9CD2E}
\definecolor{zebragreen2}{HTML}{00E000}
%    \end{macrocode}
%    \begin{macrocode}
%</package>
%    \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-goodies}
\usepackage{lipsum}
\pagestyle{empty}
\begin{document}
\section{Demo name\comment{revise the name}}
\lipsum[1] \todo[alice]{revise the introduction}

\lipsum[2] \note[bob]{add a reference here}
\lipsum[3] \fixed[carol]{looks good now}
\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
