3

In the following toy example, I would like to use __ and ^^ instead of - and .. Is it possible?

\documentclass[varwidth, border = 3pt]{standalone}

\NewDocumentCommand{\hyperseq}{ m e_ e^ e- e. }{%
  $%
    {}%
    \IfValueT{#4}{_{#4}}%
    \IfValueT{#5}{^{#5}}%
    #1%
    \IfValueT{#2}{_{#2}}%
    \IfValueT{#3}{^{#3}}%
  $
}

\begin{document}

\hyperseq{u}

\hyperseq{u}_{1}

\hyperseq{u}_{1}^{2}

\hyperseq{u}_{1}^{2}-{3}

\hyperseq{u}_{1}^{2}-{3}.{4}

\hyperseq{u}-{3}.{4}

\end{document}
3
  • 1
    Short answer:no. And you’re abusing the e argument type. Commented yesterday
  • 1
    I'm just having fun. I'm a pacifist. :-) Commented yesterday
  • It's maybe possible to realize what you're asking for, with picking commands like \peek_analysis_map_inline:n that allows you to analyze what follows your macro (see the section 25.6, Peeking ahead at the next token of the LaTeX3 interface manual). But you'll need lot of tests branches and I'm not sure it worth it. Commented 2 hours ago

4 Answers 4

4

No, for two basic reasons:

  1. e can only check one token;
  2. even if some trick could be devised, there's a fundamental problem with ^^.

When TeX is tokenizing a line of input and sees a character of category code 7 (usually ^ is assigned this code), it checks whether another identical character follows. If so, it checks whether the two following characters are among 0123456789abcdef; upon finding them it acts as if the input contained the character with ASCII code expressed by the two found characters interpreted as a number in hexadecimal format. Otherwise it looks at the following character, checks its ASCII code and inserts the character having code either 64 less or 64 more (depending on what alternative doesn't go beyond the interval [0,127]).

(Note: in LuaTeX or XeLaTeX there can be up to six consecutive ^ characters which start the procedure, but it's the same.)

Thus, even if you concocted a method for an extended “embellishment” argument type checking two characters, this would fail when

^^{

is input, because, according to the above rules, TeX would see ; to begin with: the ASCII code of { is 123 and subtracting 64 yields 59, the ASCII code of the semicolon.

OK, one could change the category code of ^… Would you try? I wouldn't.

The first basic reason remains.

3
  • The doc usrguide should be fixes because it is written "Given as e{⟨tokens⟩}". Thanks for the explanations. Commented yesterday
  • 2
    @projetmbc No, to allow mixed order of embelishments, you'd use e{^_} for example Commented yesterday
  • You are (W)right. :-) It is written "a set of optional". Commented yesterday
4

You can't use ^^ but you could use \_ and \^ note you should put them all inside the same e{...}

enter image description here

\documentclass[varwidth, border = 3pt]{standalone}

\NewDocumentCommand{\hyperseq}{ m e{_^\_\^} }{%
  $%
    {}%
    \IfValueT{#4}{_{#4}}%
    \IfValueT{#5}{^{#5}}%
    #1%
    \IfValueT{#2}{_{#2}}%
    \IfValueT{#3}{^{#3}}%
  $
}

\begin{document}

\hyperseq{u}

\hyperseq{u}_{1}

\hyperseq{u}_{1}^{2}

\hyperseq{u}_{1}^{2}\_{3}

\hyperseq{u}_{1}^{2}\_{3}\^{4}

\hyperseq{u}\_{3}\^{4}

\end{document}
2
  • That looks good. Thanks. Commented 16 hours ago
  • 2
    @projetmbc the important part is that if egreg and I both post, the tick goes in the right direction. Commented 16 hours ago
3

The only solution here is to change the API: see @egreg's answer. Here is a proposition.

\documentclass[varwidth, border = 3pt]{standalone}

\NewDocumentCommand{\hyperseq}{ m ed eu eD eU }{%
  $%
    {}%
    \IfValueT{#4}{_{#4}}%
    \IfValueT{#5}{^{#5}}%
    #1%
    \IfValueT{#2}{_{#2}}%
    \IfValueT{#3}{^{#3}}%
  $
}

\begin{document}

\hyperseq{u}

\hyperseq{u}d{1}

\hyperseq{u}d{1}u{2}

\hyperseq{u}d{1}u{2}D{3}

\hyperseq{u}d{1}u{2}D{3}U{4}

\hyperseq{u}D{3}U{4}

\end{document}

enter image description here

PS: for a real API, here is a better solution.

\documentclass[varwidth, border = 3pt]{standalone}

\NewDocumentCommand{\hyperseq}{ m o d() d<> d++ }{%
  $%
    {}%
    \IfValueT{#4}{_{#4}}%
    \IfValueT{#5}{^{#5}}%
    #1%
    \IfValueT{#2}{_{#2}}%
    \IfValueT{#3}{^{#3}}%
  $
}

\begin{document}

\hyperseq{u}

\hyperseq{u}[1]

\hyperseq{u}[1](2)

\hyperseq{u}[1](2)<3>

\hyperseq{u}[1](2)<3>+4+

\hyperseq{u}<3>+4+

\end{document}
0

Another API suggestion: as your command typesets scripts before some content, you could use another e{_^} embellishment before the mandatory argument

\NewDocumentCommand{\hyperseq}{ e{_^} m e{_^} }{%
  $%
    {}%
    \IfValueT{#1}{_{#1}}%
    \IfValueT{#2}{^{#2}}%
    #3%
    \IfValueT{#4}{_{#4}}%
    \IfValueT{#5}{^{#5}}%
  $
}

Example:

\documentclass[varwidth, border = 3pt]{standalone}

\NewDocumentCommand{\hyperseq}{ e{_^} m e{_^} }{%
  $%
    {}%
    \IfValueT{#1}{_{#1}}%
    \IfValueT{#2}{^{#2}}%
    #3%
    \IfValueT{#4}{_{#4}}%
    \IfValueT{#5}{^{#5}}%
  $
}

\begin{document}

\hyperseq{u}

\hyperseq{u}_{1}

\hyperseq{u}_{1}^{2}

\hyperseq_{3}{u}_{1}^{2}

\hyperseq_{3}^{4}{u}_{1}^{2}

\hyperseq_{3}^{4}{u}

\end{document}

Example

2
  • 1
    I'd do e{_^}, so it's immaterial which one comes first. Commented 32 mins ago
  • @egreg Yes, thank you. I need to revise my usrguide. Fixed. Commented 15 mins ago

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.