GithubHelp home page GithubHelp logo

Comments (4)

muzimuzhi avatar muzimuzhi commented on May 28, 2024

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.

Sophanatprime avatar Sophanatprime commented on May 28, 2024

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.

muzimuzhi avatar muzimuzhi commented on May 28, 2024

BTW \__kernel... is still an internal name. \cmd_... is OK but I doubt LaTeX2e kernel will provide such one in short term.

from latex2e.

josephwright avatar josephwright commented on May 28, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.