latex3 / latex2e

The LaTeX2e kernel
https://www.latex-project.org/
LaTeX Project Public License v1.3c
1.94k stars 267 forks source link

Feature request: p argument specification for document command #1098

Closed Sophanatprime closed 1 year ago

Sophanatprime commented 1 year ago

Brief outline of the enhancement

I would like to propose a new argument specification for ltcmd: p, which is used to test if one of the tokens in a token list appears in the input. This would be useful for cases where we want to check if one of several tokens is present, without using multiple t arguments. For example, if we define \NewDocumentCommand\foo{ p{+-*} }{#1}, then \foo - and \foo\relax would give 2 and 0, respectively.

Minimal example showing the desired new behaviour

\RequirePackage{latexbug}
\documentclass{article}

\NewDocumentCommand \foo { p{+-*} } {#1}
% or maybe 
% \def\foolist{+-*}
% \NewDocumentCommand \foo { P\foolist } {#1}

% just showcase
\DeclareDocumentCommand \abs { p{*\big\Big\bigg\Bigg} m }
  {\ifcase #1 \left\|#2\right\|
    \or #2
    \or \bigl \|#2\bigr \|
    \or \Bigl \|#2\Bigr \|
    \or \biggl\|#2\biggr\|
    \or \Biggl\|#2\Biggr\|
    \fi
  }

\begin{document}

\foo + % leaves 1
\foo * % leaves 3
\foo\relax % leaves 0, does not appear

\abs{A}
\abs*{A}
\abs\big{A}

\end{document}
github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity.

josephwright commented 1 year ago

The aim of ltcmd is to provide a generic way to define commands with a 'LaTeX-like' interface. The proposal here is outside this area, so after discussion we have decided to turn this down.