Hot answers tagged

7 votes
Accepted

Find the highest year in a string

The year is extracted with the regular expression [0-9]{4}. With \regex_extract_all:nnN all matches are stored in the sequence \l__Skay_dates_seq. This sequence is used with \seq_use:Nn and a , ...
matexmatics's user avatar
  • 3,734
6 votes
Accepted

Counting the number of occurences of specific characters in a string in an expandable way

\documentclass{article} \def\countsep#1#2{\the\numexpr0\countsepy#1\Endlist#2\Endcount} \def\countsepy#1#2\Endlist#3\Endcount{\countsepz#1#3\Endcount \ifx\relax#2\relax\relax\else\countsepy#2\...
Steven B. Segletes's user avatar
5 votes
Accepted

Add aliases for command while defining command

It's a problem of # doubling. You can also avoid setting a sequence. \documentclass{article} \usepackage{amsmath} \ExplSyntaxOn \NewDocumentCommand { \NewDocumentCommands } { m m m } { \tl_set:...
egreg's user avatar
  • 1.1m
5 votes

How to print the number of elements in the first and second rows of an array respectively?

Using listofitems, instead of expl3: \documentclass{article} \usepackage{listofitems} \newtoks\zz \newcommand\addtozz[1]{\global\zz\expandafter{\the\zz#1}} \newcommand\xaddtozz[1]{\expandafter\addtozz\...
Steven B. Segletes's user avatar
5 votes

Latex3: Passing empty token list to another command and detecting it as empty token list

If you use \tl_if_eq:nnTF {#1} { \c_novalue_tl } you're comparing these tokens exactly, so only a #1 that contains exactly \c_novalue_tl is true (so \tmp:n { \c_novalue_tl } with \tmp:n containing ...
Skillmon's user avatar
  • 59.6k
4 votes

Latex3: Passing empty token list to another command and detecting it as empty token list

\c_novalue_tl is a very specific token list that cannot be used to test for emptiness. You should expand the arguments before passing them to \amc (that I made an internal command, for this purpose). \...
egreg's user avatar
  • 1.1m
4 votes
Accepted

A macro to check command expandability

I think the basic misunderstanding is Basically, the \color command does the kind of job I'm looking for, The \color command does no checks of the type requested, it simply expects that after ...
David Carlisle's user avatar
4 votes

Counting the number of occurences of specific characters in a string in an expandable way

Here's a LuaLaTeX-based solution for \countsep. The solution is a simple refinement of a solution I gave to the earlier query mentioned in the OP's posting. Note that \countsep is expandable because \...
Mico's user avatar
  • 503k
3 votes
Accepted

Nest Latex3 data arrays

The fact that you get no error is irrelevant. Apart from registers, TeX only knows how to store material in macros and \l_my_dict_prop is a macro, as is \l_myarray_tl. If you add \tl_show:N \...
egreg's user avatar
  • 1.1m
3 votes

Problems testing for a leap year using expl3

We can solve this task without expl3, but using Lua in LuaTeX: \edef\nbb{\string\\} \edef\%{\csstring\%} \def\isleap#1\iftrue{\directlua{ if #1\%4 > 0 then tex.print("\nbb iffalse") ...
wipet's user avatar
  • 73.4k
3 votes

A macro to check command expandability

To debug your code, I'd just use \typeout. \documentclass[preview = true, varwidth = true]{standalone} \usepackage{xcolor} \newcommand{\expandable}[1]{#1} \newcommand{\notexpandable}[1]{% \edef\...
user202729's user avatar
  • 6,953
2 votes
Accepted

Branch to something when an expression cannot be evaluated by fpeval

If expandability is not a requirement, you can check the syntax using a regex \documentclass[preview = true, varwidth = true]{standalone} % These only needed in old latex releases % \usepackage{...
David Carlisle's user avatar
2 votes
Accepted

In expl3, how to test if something, once fully expanded, contains any character belonging to classes 11 or 12?

Assuming we can treat brace groups at the top level only, anbd that {E} is equivalent to E, then we can do \ExplSyntaxOn \prg_new_conditional:Npnn \vincent_if_blank:n #1 { p , T , F , TF } { \...
Joseph Wright's user avatar
  • 259k
2 votes

Find the highest year in a string

I'd go with expl3 all along. \documentclass{article} \ExplSyntaxOn \NewDocumentCommand{\primarySection}{O{primary}mmmmm} { \__sky_year_extract:n { #5 } \int_compare:nTF { \c_sys_year_int - 5 &...
egreg's user avatar
  • 1.1m
2 votes

How to do an if after an `exp:args` in expl3

I wouldn't do it this way myself, but the following code works with relatively conservative changes to your original. \documentclass{standalone} \usepackage{tikz} % From [this answer by @...
cfr's user avatar
  • 197k
2 votes

stop integer from expanding when using \seq_item

The solution is to use \seq_put_right:Ne (or Nx) instead, to fully expand the inserted item before adding it to the sequence. The o type performs a single expansion, which isn't enough where you are ...
JSLee's user avatar
  • 21
2 votes

Counting the number of occurences of specific characters in a string in an expandable way

The following implements this in L3 using etl. It does use the required argument in brackets of your question, though I strongly advice against it. Using non-standard arguments is discouraged for a ...
Skillmon's user avatar
  • 59.6k
2 votes
Accepted

How to print the number of elements in the first and second rows of an array respectively?

You can make better use of expl3 so you can define as many arrays as you want and retrieve information from them in a uniform way. As a general rule, don't mix \gdef with expl3. Note that the “step 2” ...
egreg's user avatar
  • 1.1m
1 vote

Demonstrating expansion in using l3

If you want to demonstrate V/v, I would construct two parallel examples, one set using macros and one using registers - toks would be most similar. This will then show that V/v type expansion only ...
Joseph Wright's user avatar
  • 259k
1 vote
Accepted

How to do an if after an `exp:args` in expl3

You can do: \ExplSyntaxOn % There is no point in doing \NewExpandableDocument as \clist_set:Nn and % \clist_pop:NN and \clist_map_inline:Nn are not fully expandable. \NewDocumentCommand{\...
Ulrich Diez's user avatar
  • 28.2k
1 vote

Problems testing for a leap year using expl3

Here is a solution that uses the \int_case: function. In my opinion, this allows for a more condensed, more readable code structure. \documentclass{article} \ExplSyntaxOn \prg_new_conditional:Npnn \...
User23456234's user avatar
  • 1,727
1 vote

Problem with a command that prefixes words only if needed when the arguments are provided through macros

A better programming style is to define the user level command in terms of an internal function. \documentclass{article} \ExplSyntaxOn \NewExpandableDocumentCommand { \forcebeginwith } { m m } { \...
egreg's user avatar
  • 1.1m
1 vote

Problems testing for a leap year using expl3

Just for comparison. What we can do with classical plain TeX (without Lua): \newcount\modresult \newif\ifleap \def\modulo #1#2 {\modresult=#1\relax \divide\modresult by#2 \multiply\modresult by-#...
wipet's user avatar
  • 73.4k

Only top scored, non community-wiki answers of a minimum length are eligible