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}
2
  • 1
    Short answer:no. And you’re abusing the e argument type. Commented 22 hours ago
  • 1
    I'm just having fun. I'm a pacifist. :-) Commented 22 hours ago

3 Answers 3

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 21 hours ago
  • 2
    @projetmbc No, to allow mixed order of embelishments, you'd use e{^_} for example Commented 21 hours ago
  • You are (W)right. :-) It is written "a set of optional". Commented 21 hours ago
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 12 hours ago
  • 2
    @projetmbc the important part is that if egreg and I both post, the tick goes in the right direction. Commented 12 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}

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.