Comments (4)
I interpret your need as "exposing the logic of =
argument modifier in ltcmd
module as a public latex3 conditional function, which checks whether an n
-type argument is in key-value format or not in the same way =
modifier does". (The documentation of =
modifier can be found in texdoc usrguide
(2023-05-23), sec. 2.9 "Auto-converting to key–value format".)
I think the quickest way is implementing a modified version of \__cmd_arg_to_keyvalue:nn
in your code.
Can you give some precise use cases which are not covered by =
modifier?
from latex2e.
The main reason is document command is rather slower than a usual macro, it executes many unnecessary codes for this demand.
\documentclass{article}
\ExplSyntaxOn
\cs_new:Npn \__kernel_set_arg_to_keyvalue:Nnn #1#2#3
{
\__cmd_arg_to_keyvalue:nn {#2} {#3}
\tl_set_eq:NN #1 \ProcessedArgument
}
\tl_new:N \l__my_keyvalue_tl
\scan_new:N \s__my_mark
\cs_new_protected:Npn \__my_if_keyvalue:nTF #1#2#3
{
\__kernel_set_arg_to_keyvalue:Nnn \l__my_keyvalue_tl { \s__my_mark } {#1}
\str_if_eq:eeTF { \s__my_mark } { \tl_head:N \l__my_keyvalue_tl }
{#3} {#2}
}
\NewDocumentCommand \__mz_if_keyvalue:nTF { ={\s__my_mark} +m +m +m }
{
\str_if_eq:eeTF { \s__my_mark } { \tl_head:n {#1} }
{#3} {#2}
}
\ExplSyntaxOff
\usepackage{l3benchmark}
\begin{document}
\ExplSyntaxOn
\benchmark_tic:
\prg_replicate:nn { 10000 }
{ \__my_if_keyvalue:nTF {aa=b,hudiw=dwuiahud,ajwdihfuawijdaodhawdfe,aa=b } {}{} }
\benchmark_toc:
\benchmark_tic:
\prg_replicate:nn { 10000 }
{ \__mz_if_keyvalue:nTF {aa=b,hudiw=dwuiahud,ajwdihfuawijdaodhawdfe,aa=b } {}{} }
\benchmark_toc:
\benchmark_tic:
\prg_replicate:nn { 10000 }
{ \__my_if_keyvalue:nTF {aa=b,hudiw=dwuiahud,ajwdihfuawijdaodhawdfe,aa=b } {}{} }
\benchmark_toc:
\benchmark_tic:
\prg_replicate:nn { 10000 }
{ \__mz_if_keyvalue:nTF {aa=b,hudiw=dwuiahud,ajwdihfuawijdaodhawdfe,aa=b } {}{} }
\benchmark_toc:
\ExplSyntaxOff
\end{document}
and the result is
(l3benchmark) + TOC: 0.305 s %% plain macro
(l3benchmark) + TIC
(l3benchmark) + TOC: 0.678 s %% document command
(l3benchmark) + TIC
(l3benchmark) + TOC: 0.311 s %% plain macro
(l3benchmark) + TIC
(l3benchmark) + TOC: 0.664 s %% document command
in my laptop (with pdflatex). Of course, for longer arguments, the gap has narrowed.
from latex2e.
BTW \__kernel...
is still an internal name. \cmd_...
is OK but I doubt LaTeX2e kernel will provide such one in short term.
from latex2e.
At present, the use case here does not really seem to justify adding this: yes document commands are slower than 'raw' macros, but there are reasons.
from latex2e.
Related Issues (20)
- fpeval expands past its argument HOT 2
- amsmath: `{align}` inherits line-depth of above `{gather}`, results in incorrect vertical placement tags HOT 3
- `\disable@package@load` ready to be used by third-party classes? HOT 1
- \if@reversemargin wrongly documented in source code HOT 1
- expansion of key-value package options differ on the first and second call HOT 2
- \IfInstanceExistTF unavailable in 2024-06-01 pre-release 1 HOT 9
- Adding a .dir-locals.el to the project root directory HOT 5
- \afterpage from afterpage package broken with recent distribution HOT 3
- Changes in horizontal spacing in some equations HOT 3
- CamelCase or Pascal case? HOT 3
- array package exhibits a surprising spacing difference when math cells end in explicit spaces
- `flushright` isn't right in rtl paragraphs HOT 13
- Loading `textcomp` turns `LaTeX Info` messages into `Package textcomp Info` messages HOT 22
- Rollback declarations should be improved in several files HOT 2
- \textcircled and TS1 missing circle. HOT 2
- \resizebox* mentioned but unexplained in grfguide? HOT 6
- Error in multicolumn environment with footnotes per page HOT 1
- Incorrect numbering and positioning of footnotes with multicols environment. HOT 5
- \overrightarrow and \overleftarrow paragraph start + documentation HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from latex2e.