시퀀스 생성을 위한 매크로

시퀀스 생성을 위한 매크로

저는 시퀀스의 일반 용어를 입력받아 시퀀스를 광범위하게 작성하는 매크로를 찾고 있습니다.

내 말은 명령입니다 \GenSeq{general term}{index}{min index}{max index}. 예를 들어

\GenSeq{f(i)}{i}{1}{n} 생산하다

여기에 이미지 설명을 입력하세요

\GenSeq{f(i)}{i}{k}{n} 생산하다

여기에 이미지 설명을 입력하세요

\GenSeq{\theta^{(s)}}{s}{s}{T}

여기에 이미지 설명을 입력하세요

라텍스로 이런게 프로그래밍이 가능한지 궁금하네요

답변1

여기에 이미지 설명을 입력하세요

\documentclass{article}

\def\GenSeq#1#2#3{%
\def\zz##1{#1}%
\def\zzstart{#2}%
\zz{#2},
\ifx\zzstart\zzzero\zz{1}\else\ifx\zzstart\zzone\zz{2}\else\zz{#2+1}\fi\fi,
\ldots,\zz{#3}}
\def\zzzero{0}
\def\zzone{1}
\begin{document}

\parskip\bigskipamount

$\GenSeq{f(#1)}{1}{n}$

$\GenSeq{f(#1)}{k}{n}$

$\GenSeq{\theta^{(#1)}}{s}{T}$

\end{document}

답변2

.expl3

의 첫 번째 필수 인수는 "루프"의 현재 인덱스를 나타내는 \GenSeq템플릿입니다 . #1두 번째 인수는 시작점, 세 번째 인수는 끝점입니다.

두 번째 인수가 정수(정규식, 0개 또는 1개의 하이픈/빼기 기호 및 1개 이상의 숫자를 통해 인식됨)인 경우 두 번째 인쇄된 항목의 색인이 계산됩니다. 그렇지 않으면 다음과 같습니다.<start point>+1 . 하지만

  1. 시작점과 끝점이 일치하면 하나의 항목만 인쇄됩니다.
  2. 시작점이 숫자이고 종료점도 숫자이고 1~2만큼 차이가 나면 해당 항목만 인쇄됩니다.
  3. 그렇지 않으면 시작 항목, 다음 항목, 점 및 종료 항목이 인쇄됩니다.

를 사용하면 \GenSeq*끝 부분에 점이 추가되어 무한 시퀀스를 나타냅니다.

\documentclass{article}
\usepackage{amsmath}
%\usepackage{xparse} % not needed with LaTeX 2020-10-01 or later

\ExplSyntaxOn

\NewDocumentCommand{\GenSeq}{smmm}
 {% #1 = optional *
  % #2 = template
  % #3 = starting point
  % #4 = end point
  \pinkcollins_genseq:nnn { #2 } { #3 } { #4 }
  \IfBooleanT{#1}{,\dotsc}
 }

\cs_new_protected:Nn \pinkcollins_genseq:nnn
 {
  % turn the template into a (temporary) function
  \cs_set:Nn \__pinkcollins_genseq_temp:n { #1 }
  % do the main work
  \tl_if_eq:nnTF { #2 } { #3 } 
   {% if #2=#3, not much to do
    \__pinkcollins_genseq_temp:n { #2 }
   }
   {% now the hard work
    \__pinkcollins_genseq_do:nn { #2 } { #3 }
   }
 }

\cs_new_protected:Nn \__pinkcollins_genseq_do:nn
 {% #1 = start point, #2 = end point
  % first check whether #1 is an integer
  % \-? = one optional minus sign
  % [[:digit:]]+ = one or more digits
  % \Z = up to the end of the input
  \regex_match:nnTF { \-? [[:digit:]]+ \Z } { #1 }
   {
    \__pinkcollins_genseq_number:nn { #1 } { #2 }
   }
   {
    \__pinkcollins_genseq_symbolic:nn { #1 } { #2 }
   }
 }

\cs_new_protected:Nn \__pinkcollins_genseq_number:nn
 {% #1 = start point, #2 = end point
  \tl_if_eq:enTF { \int_eval:n { #1 + 1 } } { #2 }
   {
    \__pinkcollins_genseq_temp:n { #1 },\__pinkcollins_genseq_temp:n { #2 }
   }
   {
    \__pinkcollins_genseq_temp:n { #1 },
    \__pinkcollins_genseq_temp:n { \int_eval:n { #1+1 } },
    \tl_if_eq:enF { \int_eval:n { #1 + 2 } } { #2 } { \dots, }
    \__pinkcollins_genseq_temp:n { #2 }
   }
 }
\prg_generate_conditional_variant:Nnn \tl_if_eq:nn { e } { T, F, TF }

\cs_new_protected:Nn \__pinkcollins_genseq_symbolic:nn
 {% #1 = start point, #2 = end point
  \__pinkcollins_genseq_temp:n { #1 },
  \__pinkcollins_genseq_temp:n { #1+1 },
  \dots,
  \__pinkcollins_genseq_temp:n { #2 }
 }

\ExplSyntaxOff

\begin{document}

$\GenSeq{f(#1)}{1}{n}$

$\GenSeq{f(#1)}{0}{n}$

$\GenSeq{f(#1)}{1}{1}$

$\GenSeq{f(#1)}{1}{2}$

$\GenSeq{f(#1)}{1}{3}$

$\GenSeq{f(#1)}{1}{4}$

$\GenSeq{f(#1)}{-2}{k}$

$\GenSeq{f(#1)}{k}{n}$

$\GenSeq*{\theta^{(#1)}}{s}{T}$

\end{document}

여기에 이미지 설명을 입력하세요


-variant 의 다른 사용법은 *시퀀스를 내림차순으로 만드는 것입니다.

\documentclass{article}
\usepackage{amsmath}
%\usepackage{xparse} % not needed with LaTeX 2020-10-01 or later

\ExplSyntaxOn

\NewDocumentCommand{\GenSeq}{smmm}
 {% #1 = optional * for reverse sequence
  % #2 = template
  % #3 = starting point
  % #4 = end point
  \IfBooleanTF{#1}
   {
    \cs_set:Nn \__pinkcollins_genseq_sign: { - }
   }
   {
    \cs_set:Nn \__pinkcollins_genseq_sign: { + }
   }
  \pinkcollins_genseq:nnn { #2 } { #3 } { #4 }
 }

\cs_new_protected:Nn \pinkcollins_genseq:nnn
 {
  % turn the template into a (temporary) function
  \cs_set:Nn \__pinkcollins_genseq_temp:n { #1 }
  % do the main work
  \tl_if_eq:nnTF { #2 } { #3 } 
   {% if #2=#3, not much to do
    \__pinkcollins_genseq_temp:n { #2 }
   }
   {% now the hard work
    \__pinkcollins_genseq_do:nn { #2 } { #3 }
   }
 }

\cs_new_protected:Nn \__pinkcollins_genseq_do:nn
 {% #1 = start point, #2 = end point
  % first check whether #1 is an integer
  % \-? = one optional minus sign
  % [[:digit:]]+ = one or more digits
  % \Z = up to the end of the input
  \regex_match:nnTF { \-? [[:digit:]]+ \Z } { #1 }
   {
    \__pinkcollins_genseq_number:nn { #1 } { #2 }
   }
   {
    \__pinkcollins_genseq_symbolic:nn { #1 } { #2 }
   }
 }

\cs_new_protected:Nn \__pinkcollins_genseq_number:nn
 {% #1 = start point, #2 = end point
  \tl_if_eq:enTF { \int_eval:n { #1 \__pinkcollins_genseq_sign: 1 } } { #2 }
   {
    \__pinkcollins_genseq_temp:n { #1 },\__pinkcollins_genseq_temp:n { #2 }
   }
   {
    \__pinkcollins_genseq_temp:n { #1 },
    \__pinkcollins_genseq_temp:n { \int_eval:n { #1\__pinkcollins_genseq_sign: 1 } },
    \tl_if_eq:enF { \int_eval:n { #1 \__pinkcollins_genseq_sign: 2 } } { #2 } { \dots, }
    \__pinkcollins_genseq_temp:n { #2 }
   }
 }
\prg_generate_conditional_variant:Nnn \tl_if_eq:nn { e } { T, F, TF }

\cs_new_protected:Nn \__pinkcollins_genseq_symbolic:nn
 {% #1 = start point, #2 = end point
  \__pinkcollins_genseq_temp:n { #1 },
  \__pinkcollins_genseq_temp:n { #1\__pinkcollins_genseq_sign:1 },
  \dots,
  \__pinkcollins_genseq_temp:n { #2 }
 }

\ExplSyntaxOff

\begin{document}

\textbf{Ascending}

$\GenSeq{f(#1)}{1}{n}$

$\GenSeq{f(#1)}{0}{n}$

$\GenSeq{f(#1)}{1}{1}$

$\GenSeq{f(#1)}{1}{2}$

$\GenSeq{f(#1)}{1}{3}$

$\GenSeq{f(#1)}{1}{4}$

$\GenSeq{f(#1)}{-2}{k}$

$\GenSeq{f(#1)}{k}{n}$

$\GenSeq{\theta^{(#1)}}{s}{T}$

\textbf{Descending}

$\GenSeq*{f(#1)}{n}{1}$

$\GenSeq*{f(#1)}{n}{0}$

$\GenSeq*{f(#1)}{1}{1}$

$\GenSeq*{f(#1)}{2}{1}$

$\GenSeq*{f(#1)}{3}{1}$

$\GenSeq*{f(#1)}{4}{1}$

$\GenSeq*{f(#1)}{k}{-2}$

$\GenSeq*{f(#1)}{k}{n}$

$\GenSeq*{\theta^{(#1)}}{s}{T}$

\end{document}

여기에 이미지 설명을 입력하세요

답변3

expl3을 가지고 재미있게 놀기 위해 나는 expl3을 사용하고 싶었습니다.

하지만 결국 expl3과 내 코드를 혼합하여 작업을 수행했습니다.

  • 나는 expl3-regex-code를 사용하여 확인합니다.⟨최소 지수⟩—⁠(!)⁠ ⁠토큰 확장 없이⟨최소 지수⟩⁠ ⁠(!)⁠—최대 1개의 부호와 일부 소수의 시퀀스를 형성하며, 그렇다면 다음의 (증가된) 값을 증가시키고 대체 루틴에 전달합니다.⟨최소 지수⟩.
  • 교체를 위해 내 자신의 코드를 사용합니다.⟨색인⟩이내에⟨일반 용어⟩.

⟨최소 지수⟩유효한 TeX-를 표시/생성하는지 확인하기 위해 확장되지 않았습니다.⟨숫자⟩-수량. 나는 다음과 같은 이유로 그러한 확인/테스트에 대한 아이디어를 거부합니다. 완전히 확장되었는지 여부를 확인하는 테스트 방법이 없습니다.⟨최소 지수⟩유효한 TeX-만 생성합니다.⟨숫자⟩-어떤 방식으로든 결함이 없거나 가능한 사용자 입력에 제한을 두지 않는 수량을 알고 있습니다. 이러한 테스트를 위한 알고리즘을 구현하려고 하면 중단 문제에 직면하게 됩니다. 확장할 때 토큰이 형성됩니다.⟨최소 지수⟩임의의 확장 기반 알고리즘을 형성할 수 있습니다. 알고리즘을 사용하면 그러한 알고리즘이 결국 유효한 TeX-를 생성하는지 여부를 확인할 수 있습니다.⟨숫자⟩-수량은 알고리즘이 다른 임의의 알고리즘이 모두 종료되는지/오류 메시지 없이 종료되는지 확인하는 것을 의미합니다. 이것이 정지 문제입니다.앨런 튜링은 1936년에 증명했습니다.임의의 알고리즘에 대해 해당 알고리즘이 종료될지 여부를 "결정"할 수 있는 알고리즘을 구현하는 것은 불가능합니다.

처음에는 교체를 하려고 했으나⟨색인⟩expl3-routines을 사용하여 다음을 수행할 수도 있습니다.

파트 VII - l3tl 패키지 - 토큰 목록, 부분3 토큰 목록 변수 수정~의인터페이스3.pdf(2020-10-27 출시)은 다음과 같이 말합니다.

\tl_replace_all:Nnn ⟨tl var⟩ {⟨old tokens⟩} {⟨new tokens⟩}

대체모든 발생~의⟨오래된 토큰⟩에서⟨tl 변수⟩~와 함께⟨새로운 토큰⟩.⟨오래된 토큰⟩또는 {( 더 정확하게는 범주 코드 1(시작 그룹) 또는 2(끝 그룹)의 명시적 문자 토큰과 범주 코드 6의 토큰)을 포함할 수 없습니다 . 이 기능은 왼쪽에서 오른쪽으로 작동하므로 패턴은}#⟨오래된 토큰⟩교체 후에도 남아 있을 수 있습니다( \tl_remove_all:Nn예는 참조).

(카테고리 코드 1이 "begin-group"이고 카테고리 코드 2가 "end-group"이라고 들었습니다. 카테고리 코드 6이 "매개 변수"라고 말하지 않은 이유가 궁금합니다. ;-) )

으로 해보았습니다 \tl_replace_all:Nnn.

그러나 이 진술은 사실이 아니기 때문에 실패했습니다.

(직접 테스트해 볼 수 있습니다.

아래 예에서 모든 get 항목이 u다음으로 대체되는 것은 아닙니다 d.

\documentclass{article}
\usepackage{expl3}
\ExplSyntaxOn
\tl_set:Nn \l_tmpa_tl {uu{uu}uu{uu}}
\tl_replace_all:Nnn \l_tmpa_tl {u} {d}
\tl_show:N \l_tmpa_tl
\stop

⟨오래된 토큰⟩이다 u.
⟨새로운 토큰⟩이다 d.
다음에 대한 모든 제한사항⟨오래된 토큰⟩그리고⟨새로운 토큰⟩순종된다.

콘솔 출력은 다음과 같습니다

\l_tmpa_tl=dd{uu}dd{uu}.

범주 코드 1(시작 그룹) 및 2(끝 그룹)와 일치하는 명시적 문자 토큰 쌍 사이에 중첩되지 않은 항목만 대체되는 것으로 보입니다.

따라서 모든 발생이 대체된다는 진술은 잘못된 것입니다.

명령문이 올바른 경우 콘솔 출력은 다음과 같습니다.

\l_tmpa_tl=dd{dd}dd{dd}.

)

\ReplaceAllIndexOcurrences그래서 나는 expl3 없이 처음부터 내 자신의 교체 루틴을 작성하기로 결정했습니다 .

부작용으로 인해 범주 코드 1의 모든 명시적 문자 토큰은 으로 , 범주 코드 2의 모든 명시적 문자 토큰은 으로 \ReplaceAllIndexOcurrences대체됩니다 .{1}2

\documentclass[landscape, a4paper]{article}

%===================[adjust margins/layout for the example]====================
\csname @ifundefined\endcsname{pagewidth}{}{\pagewidth=\paperwidth}%
\csname @ifundefined\endcsname{pdfpagewidth}{}{\pdfpagewidth=\paperwidth}%
\csname @ifundefined\endcsname{pageheight}{}{\pageheight=\paperheight}%
\csname @ifundefined\endcsname{pdfpageheight}{}{\pdfpageheight=\paperheight}%
\textwidth=\paperwidth
\oddsidemargin=1.5cm
\marginparsep=.2\oddsidemargin
\marginparwidth=\oddsidemargin
\advance\marginparwidth-2\marginparsep
\advance\textwidth-2\oddsidemargin
\advance\oddsidemargin-1in
\evensidemargin=\oddsidemargin
\textheight=\paperheight
\topmargin=1.5cm
\footskip=.5\topmargin
{\normalfont\global\advance\footskip.5\ht\strutbox}%
\advance\textheight-2\topmargin
\advance\topmargin-1in
\headheight=0ex
\headsep=0ex
\pagestyle{plain}
\parindent=0ex
\parskip=0ex 
\topsep=0ex
\partopsep=0ex
%==================[eof margin-adjustments]====================================

\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand\GenSeq{mmmm}{
  \group_begin:
  % #1 = general term
  % #2 = index
  % #3 = min index
  % #4 = max index
  \regex_match:nnTF { ^[\+\-]?\d+$ }{ #3 }{
    \int_step_inline:nnnn {#3}{1}{#3+1}{\ReplaceAllIndexOcurrences{#1}{#2}{##1},}
  }{
   \ReplaceAllIndexOcurrences{#1}{#2}{#3},
   \ReplaceAllIndexOcurrences{#1}{#2}{#3+1},
  }
  \ldots,
  \ReplaceAllIndexOcurrences{#1}{#2}{#4}
  \group_end:
}
\ExplSyntaxOff

\makeatletter
%%//////////////////// Code of my own replacement-routine: ////////////////////
%%=============================================================================
%% Paraphernalia:
%%    \UD@firstoftwo, \UD@secondoftwo,
%%    \UD@PassFirstToSecond, \UD@Exchange, \UD@removespace
%%    \UD@CheckWhetherNull, \UD@CheckWhetherBrace,
%%    \UD@CheckWhetherLeadingTokens, \UD@ExtractFirstArg
%%=============================================================================
\newcommand\UD@firstoftwo[2]{#1}%
\newcommand\UD@secondoftwo[2]{#2}%
\newcommand\UD@PassFirstToSecond[2]{#2{#1}}%
\newcommand\UD@Exchange[2]{#2#1}%
\newcommand\UD@removespace{}\UD@firstoftwo{\def\UD@removespace}{} {}%
%%-----------------------------------------------------------------------------
%% Check whether argument is empty:
%%.............................................................................
%% \UD@CheckWhetherNull{<Argument which is to be checked>}%
%%                     {<Tokens to be delivered in case that argument
%%                       which is to be checked is empty>}%
%%                     {<Tokens to be delivered in case that argument
%%                       which is to be checked is not empty>}%
%%
%% The gist of this macro comes from Robert R. Schneck's \ifempty-macro:
%% <https://groups.google.com/forum/#!original/comp.text.tex/kuOEIQIrElc/lUg37FmhA74J>
\newcommand\UD@CheckWhetherNull[1]{%
  \romannumeral\expandafter\UD@secondoftwo\string{\expandafter
  \UD@secondoftwo\expandafter{\expandafter{\string#1}\expandafter
  \UD@secondoftwo\string}\expandafter\UD@firstoftwo\expandafter{\expandafter
  \UD@secondoftwo\string}\expandafter\z@\UD@secondoftwo}%
  {\expandafter\z@\UD@firstoftwo}%
}%
%%-----------------------------------------------------------------------------
%% Check whether argument's first token is a catcode-1-character
%%.............................................................................
%% \UD@CheckWhetherBrace{<Argument which is to be checked>}%
%%                      {<Tokens to be delivered in case that argument
%%                        which is to be checked has leading
%%                        catcode-1-token>}%
%%                      {<Tokens to be delivered in case that argument
%%                        which is to be checked has no leading
%%                        catcode-1-token>}%
\newcommand\UD@CheckWhetherBrace[1]{%
  \romannumeral\expandafter\UD@secondoftwo\expandafter{\expandafter{%
  \string#1.}\expandafter\UD@firstoftwo\expandafter{\expandafter
  \UD@secondoftwo\string}\expandafter\z@\UD@firstoftwo}%
  {\expandafter\z@\UD@secondoftwo}%
}%
%%-----------------------------------------------------------------------------
%% Check whether argument's leading tokens form a specific 
%% token-sequence that does neither contain explicit character tokens of 
%% category code 1 or 2 nor contain tokens of category code 6:
%%.............................................................................
%% \UD@CheckWhetherLeadingTokens{<argument which is to be checked>}%
%%                              {<a <token sequence> without explicit 
%%                                character tokens of category code
%%                                1 or 2 and without tokens of
%%                                category code 6>}%
%%                              {<internal token-check-macro>}%
%%                              {<tokens to be delivered in case
%%                                <argument which is to be checked> has
%%                                <token sequence> as leading tokens>}%
%%                              {<tokens to be delivered in case 
%%                                <argument which is to be checked>
%%                                does not have <token sequence> as
%%                                leading tokens>}%
\newcommand\UD@CheckWhetherLeadingTokens[3]{%
  \romannumeral\UD@CheckWhetherNull{#1}{\expandafter\z@\UD@secondoftwo}{%
    \expandafter\UD@secondoftwo\string{\expandafter
    \UD@@CheckWhetherLeadingTokens#3{\relax}#1#2}{}}%
}%
\newcommand\UD@@CheckWhetherLeadingTokens[1]{%
  \expandafter\UD@CheckWhetherNull\expandafter{\UD@firstoftwo{}#1}%
  {\UD@Exchange{\UD@firstoftwo}}{\UD@Exchange{\UD@secondoftwo}}%
  {\expandafter\expandafter\expandafter\expandafter
   \expandafter\expandafter\expandafter\z@\expandafter\expandafter
   \expandafter}\expandafter\UD@secondoftwo\expandafter{\string}%
}%
%%-----------------------------------------------------------------------------
%% \UD@internaltokencheckdefiner{<internal token-check-macro>}%
%%                              {<token sequence>}%
%% Defines <internal token-check-macro> to snap everything 
%% until reaching <token sequence>-sequence and spit that out
%% nested in braces.
%%-----------------------------------------------------------------------------
\newcommand\UD@internaltokencheckdefiner[2]{%
  \@ifdefinable#1{\long\def#1##1#2{{##1}}}%
}%
\UD@internaltokencheckdefiner{\UD@InternalExplicitSpaceCheckMacro}{ }%
%%-----------------------------------------------------------------------------
%% Extract first inner undelimited argument:
%%
%%   \romannumeral\UD@ExtractFirstArgLoop{ABCDE\UD@SelDOm} yields  {A}
%%
%%   \romannumeral\UD@ExtractFirstArgLoop{{AB}CDE\UD@SelDOm} yields  {AB}
%%.............................................................................
\@ifdefinable\UD@RemoveTillUD@SelDOm{%
  \long\def\UD@RemoveTillUD@SelDOm#1#2\UD@SelDOm{{#1}}%
}%
\newcommand\UD@ExtractFirstArgLoop[1]{%
  \expandafter\UD@CheckWhetherNull\expandafter{\UD@firstoftwo{}#1}%
  {\z@#1}%
  {\expandafter\UD@ExtractFirstArgLoop\expandafter{\UD@RemoveTillUD@SelDOm#1}}%
}%
%%=============================================================================
%% \ReplaceAllIndexOcurrences{<term with <index>>}
%%                           {<index>}%
%%                           {<replacement for<index>>}%
%%
%% Replaces all <index> in <term with <index>> by <replacement for<index>>
%%
%% !!! Does also replace all pairs of matching explicit character tokens of
%%     catcode 1/2 by matching braces!!!
%% !!! <index> must not contain explicit character tokens of catcode 1 or 2 !!!
%% !!! <index> must not contain tokens of catcode 6 !!!
%% !!! Defines temporary macro \UD@temp, therefore not expandable !!!
%%-----------------------------------------------------------------------------
\newcommand\ReplaceAllIndexOcurrences[2]{%
  % #1 - <term with <index>>
  % #2 - <index>
  \begingroup
  \UD@internaltokencheckdefiner{\UD@temp}{#2}%
  \expandafter\endgroup
  \romannumeral\UD@ReplaceAllIndexOcurrencesLoop{#1}{}{#2}%
}%
\newcommand\UD@ReplaceAllIndexOcurrencesLoop[4]{%
  % Do:
  %  \UD@internaltokencheckdefiner{\UD@temp}{<index>}%
  %  \romannumeral\UD@ReplaceAllIndexOcurrencesLoop
  %                                 {<term with <index>>}%
  %                                 {<sequence created so far, initially empty>}%
  %                                 {<index>}%
  %                                 {<replacement for<index>>}%
  %
  % #1 - <term with <index>>
  % #2 - <sequence created so far, initially empty>
  % #3 - <index>
  % #4 - <replacement for<index>>
  \UD@CheckWhetherNull{#1}{\z@#2}{%
    \UD@CheckWhetherLeadingTokens{#1}{#3}{\UD@temp}{%
      \expandafter\expandafter\expandafter\UD@ReplaceAllIndexOcurrencesLoop
      \expandafter\expandafter\expandafter{%
        \expandafter\UD@firstoftwo\expandafter{\expandafter}\UD@temp#1%
      }{#2#4}%
    }{%
      \UD@CheckWhetherLeadingTokens{#1}{ }{\UD@InternalExplicitSpaceCheckMacro}{%
         \expandafter\UD@ReplaceAllIndexOcurrencesLoop
         \expandafter{\UD@removespace#1}{#2 }%
      }{%
        \UD@CheckWhetherBrace{#1}{%
          \expandafter\expandafter\expandafter\UD@PassFirstToSecond
          \expandafter\expandafter\expandafter{%
          \expandafter\UD@PassFirstToSecond\expandafter{%
            \romannumeral\expandafter\UD@ReplaceAllIndexOcurrencesLoop
              \romannumeral\UD@ExtractFirstArgLoop{#1\UD@SelDOm}{}{#3}{#4}%
          }{#2}}%
          {\expandafter\UD@ReplaceAllIndexOcurrencesLoop\expandafter{\UD@firstoftwo{}#1}}%
        }{%
          \expandafter\UD@PassFirstToSecond\expandafter{%
            \romannumeral\expandafter\UD@Exchange\romannumeral\UD@ExtractFirstArgLoop{#1\UD@SelDOm}{\z@#2}%
          }{\expandafter\UD@ReplaceAllIndexOcurrencesLoop\expandafter{\UD@firstoftwo{}#1}}%
        }%
      }%
    }%
    {#3}{#4}%
  }%
}%
\makeatother
%%=============================================================================
%%///////////////// End of code of my own replacement-routine. ////////////////

\makeatletter
\newcommand\ParenthesesIfMoreThanOneUndelimitedArgument[1]{%
  \begingroup
  \protected@edef\UD@temp{#1}%
  \expandafter\expandafter\expandafter\UD@CheckWhetherNull
  \expandafter\expandafter\expandafter{\expandafter\UD@firstoftwo\UD@temp{}.}{%
    \endgroup#1%
  }{%
    \expandafter\UD@CheckWhetherNull
    \expandafter{\romannumeral\expandafter\expandafter
                              \expandafter            \expandafter
                              \expandafter\expandafter
                              \expandafter            \z@
                              \expandafter\expandafter
                              \expandafter            \UD@firstoftwo
                              \expandafter\UD@firstoftwo
                              \expandafter{%
                              \expandafter}%
                              \UD@temp{}.}{%
      \endgroup#1%
    }{%
      \endgroup(#1)%
    }%
  }%
}%
\makeatother

\begin{document}

Let's use \verb|i| as \textit{$\langle$index$\rangle$}---\verb|$\GenSeq{f(i)}{i}{1}{n}$| yields:

$\GenSeq{f(i)}{i}{1}{n}$

\vfill

Let's use \verb|i| as \textit{$\langle$index$\rangle$}, but \textit{$\langle$min~index$\rangle$} not a digit  sequence---\verb|$\GenSeq{f(i)}{i}{k}{n}$| yields:

$\GenSeq{f(i)}{i}{k}{n}$

\vfill

Let's use \verb|s| as \textit{$\langle$index$\rangle$}---\verb|$\GenSeq{\theta^{(s)}}{s}{s}{T}$| yields:

$\GenSeq{\theta^{(s)}}{s}{s}{T}$

\vfill

Let's use \verb|\Weird\Woozles| as \textit{$\langle$index$\rangle$}---\begin{verbatim}
$\GenSeq{%
          \sqrt{%
            \vphantom{(}%
            ParenthesesIfMoreThanOneUndelimitedArgument{\Weird\Woozles}\cdot\ParenthesesIfMoreThanOneUndelimitedArgument{\Weird\Woozles}%
            \vphantom{)}%
          }%
        }%
        {\Weird\Woozles}%
        {s}%
        {T}$
\end{verbatim} yields:

$\GenSeq{%
          \sqrt{%
            \vphantom{(}%
            \ParenthesesIfMoreThanOneUndelimitedArgument{\Weird\Woozles}\cdot\ParenthesesIfMoreThanOneUndelimitedArgument{\Weird\Woozles}%
            \vphantom{)}%
          }%
        }%
        {\Weird\Woozles}%
        {s}%
        {T}$

\vfill

Let's use the explicit space token as \textit{$\langle$index$\rangle$}---\verb|$\GenSeq{f( )}{ }{k}{n}$| yields:

$\GenSeq{f( )}{ }{k}{n}$

\vfill

Let's use the explicit space token as \textit{$\langle$index$\rangle$}---\verb|$\GenSeq{f( )}{ }{-5}{n}$| yields:

$\GenSeq{f( )}{ }{-5}{n}$

\vfill\vfill

\end{document}

여기에 이미지 설명을 입력하세요

관련 정보