How to write a definition with variants?












6















In TeX I can define, say



def1#1 is #2.{#1 & is & #2.\}



and



def2#1 has #2.{#1 & has & #2.\}



with an easy usage:
1 Jim Jones is a fictional character.
and
2 Tim Smith has two brothers.



This gives three columns of a tabular: Jim Jones, is, a fictional character. Similarly in the second case.



Can I write a definition depending on, in this case, is/has so I can write



3 Jim Jones is a fictional character.
and
3 Tim Smith has two brothers.



obtaing the previous results?



Solutions using Lua or expl3 are OK, but I hope that a pure TeX one is also possible.










share|improve this question




















  • 1





    At the TeX level for any def you can have only one parameter text (the #1 is #2. and #1 has #2. in your 1 and 2 respectively).

    – ShreevatsaR
    Mar 31 at 3:16











  • @ShreevatsaR That's why I am asking how to extend this possibility.

    – Przemysław Scherwentke
    Mar 31 at 3:36











  • @PrzemysławScherwentke What if 3 The third person singular form of have is has or 3 Be has is as the third person singular form? What should it produce? ;-)

    – L. F.
    2 days ago






  • 1





    @L.F. I have a limited number of sequences, with different words, so I know it will not happen.

    – Przemysław Scherwentke
    2 days ago











  • @PrzemysławScherwentke Never mind, just meant to be a bad joke :)

    – L. F.
    2 days ago
















6















In TeX I can define, say



def1#1 is #2.{#1 & is & #2.\}



and



def2#1 has #2.{#1 & has & #2.\}



with an easy usage:
1 Jim Jones is a fictional character.
and
2 Tim Smith has two brothers.



This gives three columns of a tabular: Jim Jones, is, a fictional character. Similarly in the second case.



Can I write a definition depending on, in this case, is/has so I can write



3 Jim Jones is a fictional character.
and
3 Tim Smith has two brothers.



obtaing the previous results?



Solutions using Lua or expl3 are OK, but I hope that a pure TeX one is also possible.










share|improve this question




















  • 1





    At the TeX level for any def you can have only one parameter text (the #1 is #2. and #1 has #2. in your 1 and 2 respectively).

    – ShreevatsaR
    Mar 31 at 3:16











  • @ShreevatsaR That's why I am asking how to extend this possibility.

    – Przemysław Scherwentke
    Mar 31 at 3:36











  • @PrzemysławScherwentke What if 3 The third person singular form of have is has or 3 Be has is as the third person singular form? What should it produce? ;-)

    – L. F.
    2 days ago






  • 1





    @L.F. I have a limited number of sequences, with different words, so I know it will not happen.

    – Przemysław Scherwentke
    2 days ago











  • @PrzemysławScherwentke Never mind, just meant to be a bad joke :)

    – L. F.
    2 days ago














6












6








6








In TeX I can define, say



def1#1 is #2.{#1 & is & #2.\}



and



def2#1 has #2.{#1 & has & #2.\}



with an easy usage:
1 Jim Jones is a fictional character.
and
2 Tim Smith has two brothers.



This gives three columns of a tabular: Jim Jones, is, a fictional character. Similarly in the second case.



Can I write a definition depending on, in this case, is/has so I can write



3 Jim Jones is a fictional character.
and
3 Tim Smith has two brothers.



obtaing the previous results?



Solutions using Lua or expl3 are OK, but I hope that a pure TeX one is also possible.










share|improve this question
















In TeX I can define, say



def1#1 is #2.{#1 & is & #2.\}



and



def2#1 has #2.{#1 & has & #2.\}



with an easy usage:
1 Jim Jones is a fictional character.
and
2 Tim Smith has two brothers.



This gives three columns of a tabular: Jim Jones, is, a fictional character. Similarly in the second case.



Can I write a definition depending on, in this case, is/has so I can write



3 Jim Jones is a fictional character.
and
3 Tim Smith has two brothers.



obtaing the previous results?



Solutions using Lua or expl3 are OK, but I hope that a pure TeX one is also possible.







macros plain-tex






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 31 at 2:58







Przemysław Scherwentke

















asked Mar 31 at 2:33









Przemysław ScherwentkePrzemysław Scherwentke

29.9k54795




29.9k54795








  • 1





    At the TeX level for any def you can have only one parameter text (the #1 is #2. and #1 has #2. in your 1 and 2 respectively).

    – ShreevatsaR
    Mar 31 at 3:16











  • @ShreevatsaR That's why I am asking how to extend this possibility.

    – Przemysław Scherwentke
    Mar 31 at 3:36











  • @PrzemysławScherwentke What if 3 The third person singular form of have is has or 3 Be has is as the third person singular form? What should it produce? ;-)

    – L. F.
    2 days ago






  • 1





    @L.F. I have a limited number of sequences, with different words, so I know it will not happen.

    – Przemysław Scherwentke
    2 days ago











  • @PrzemysławScherwentke Never mind, just meant to be a bad joke :)

    – L. F.
    2 days ago














  • 1





    At the TeX level for any def you can have only one parameter text (the #1 is #2. and #1 has #2. in your 1 and 2 respectively).

    – ShreevatsaR
    Mar 31 at 3:16











  • @ShreevatsaR That's why I am asking how to extend this possibility.

    – Przemysław Scherwentke
    Mar 31 at 3:36











  • @PrzemysławScherwentke What if 3 The third person singular form of have is has or 3 Be has is as the third person singular form? What should it produce? ;-)

    – L. F.
    2 days ago






  • 1





    @L.F. I have a limited number of sequences, with different words, so I know it will not happen.

    – Przemysław Scherwentke
    2 days ago











  • @PrzemysławScherwentke Never mind, just meant to be a bad joke :)

    – L. F.
    2 days ago








1




1





At the TeX level for any def you can have only one parameter text (the #1 is #2. and #1 has #2. in your 1 and 2 respectively).

– ShreevatsaR
Mar 31 at 3:16





At the TeX level for any def you can have only one parameter text (the #1 is #2. and #1 has #2. in your 1 and 2 respectively).

– ShreevatsaR
Mar 31 at 3:16













@ShreevatsaR That's why I am asking how to extend this possibility.

– Przemysław Scherwentke
Mar 31 at 3:36





@ShreevatsaR That's why I am asking how to extend this possibility.

– Przemysław Scherwentke
Mar 31 at 3:36













@PrzemysławScherwentke What if 3 The third person singular form of have is has or 3 Be has is as the third person singular form? What should it produce? ;-)

– L. F.
2 days ago





@PrzemysławScherwentke What if 3 The third person singular form of have is has or 3 Be has is as the third person singular form? What should it produce? ;-)

– L. F.
2 days ago




1




1





@L.F. I have a limited number of sequences, with different words, so I know it will not happen.

– Przemysław Scherwentke
2 days ago





@L.F. I have a limited number of sequences, with different words, so I know it will not happen.

– Przemysław Scherwentke
2 days ago













@PrzemysławScherwentke Never mind, just meant to be a bad joke :)

– L. F.
2 days ago





@PrzemysławScherwentke Never mind, just meant to be a bad joke :)

– L. F.
2 days ago










3 Answers
3






active

oldest

votes


















8














A listofitems approach. Also, listofitems is available in Plain TeX.



documentclass{article}
usepackage{listofitems}
defvariant#1.{%
setsepchar{is||has}%
greadlist*varinput{#1}
varinput[1] & varinputsep[1] & varinput[2].
}
begin{document}
begin{tabular}{|c|c|c|}
variant Jim Jones is a fictional character.\
variant Tim Smith has two brothers.
end{tabular}
end{document}


enter image description here



Similarly done in plain TeX



input listofitems
defvariant#1.{%
setsepchar{is||has}%
greadlist*varinput{#1}
varinput[1] & varinputsep[1] & varinput[2].
}
variant Jim Jones is a fictional character.

variant Tim Smith has two brothers.

bye





share|improve this answer
























  • Certainly +1. However, I will wait for alternative solutions. And I must reserve 3 days for reading your package. :-)

    – Przemysław Scherwentke
    Mar 31 at 3:10








  • 1





    @PrzemysławScherwentke Thanks. The package idea was mine, but the coding is all Christian's who made it come to life.

    – Steven B. Segletes
    Mar 31 at 3:14






  • 1





    @marmot I am not sure what you mean by "teach" in this context. However, look also at my tabstackengine package, which uses listofitems for parsing. It can digest matrices and remember all the cell content for future use.

    – Steven B. Segletes
    Mar 31 at 3:29






  • 1





    @marmot For example, documentclass{article} usepackage[T1]{fontenc} usepackage{listofitems} setsepchar{\/&} begin{document} readlist*myarray{x11&y12&z13\x21&y22&z_{23}\x31&y32&z33} Row 2, Col 3 = $myarray[2,3]$; tokens detokenizeexpandafterexpandafterexpandafter{myarray[2,3]} end{document}

    – Steven B. Segletes
    Mar 31 at 3:41






  • 1





    @PrzemysławScherwentke listofitems was developed in response to my ill-fated ctan.org/pkg/getargs getargs package. It was a great idea, but just didn't do what needed to be done. Christian T. took that idea and turned it into listofitems.

    – Steven B. Segletes
    Mar 31 at 3:48



















3














The replacestrings macro from OPmac can be used:



%from OPmac code:
bgroup catcode`!=3 catcode`?=3
gdefreplacestrings#1#2{longdefreplacestringsA##1#1{deftmpb{##1}replacestringsB}%
longdefreplacestringsB##1#1{ifx!##1relax elseaddtotmpb{#2##1}%
expandafterreplacestringsBfi}% improved version <May 2016> inspired
expandafterreplacestringsAtmpb?#1!#1%
longdefreplacestringsA##1?{deftmpb{##1}}expandafterreplacestringsAtmpb
}
egroup
longdefaddto#1#2{expandafterdefexpandafter#1expandafter{#1#2}}

%variant definition:
defvariant #1.{deftmpb{#1}%
replacestrings{ is }{ tabsep is tabsep }%
replacestrings{ has }{ tabsep has tabsep }%
tmpb
}
deftabsep{&}

%% test:
halign{#hfilvrulestrut &#hfilvrule &# hfilcr
%
variant Jim Jones is a fictional character. cr
variant Tim Smith has two brothers. cr
}

end





share|improve this answer































    2














    With expl3, of course. ;-)



    input expl3-generic

    ExplSyntaxOn

    cs_new_protected:Npn 3 #1.
    {
    tl_set:Nx l_tmpa_tl { tl_trim_spaces:n { #1 } }
    regex_replace_once:nnN { s*(is|has)s* } { cT& 1 cT& } l_tmpa_tl
    l_tmpa_tl. cr
    }

    ExplSyntaxOff

    halign{#hfil& hfil#hfil &# hfilcr
    3 Jim Jones is a fictional character and is funny.
    3 Tim Smith has two brothers.
    }

    bye


    enter image description here






    share|improve this answer
























      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "85"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f482357%2fhow-to-write-a-definition-with-variants%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      8














      A listofitems approach. Also, listofitems is available in Plain TeX.



      documentclass{article}
      usepackage{listofitems}
      defvariant#1.{%
      setsepchar{is||has}%
      greadlist*varinput{#1}
      varinput[1] & varinputsep[1] & varinput[2].
      }
      begin{document}
      begin{tabular}{|c|c|c|}
      variant Jim Jones is a fictional character.\
      variant Tim Smith has two brothers.
      end{tabular}
      end{document}


      enter image description here



      Similarly done in plain TeX



      input listofitems
      defvariant#1.{%
      setsepchar{is||has}%
      greadlist*varinput{#1}
      varinput[1] & varinputsep[1] & varinput[2].
      }
      variant Jim Jones is a fictional character.

      variant Tim Smith has two brothers.

      bye





      share|improve this answer
























      • Certainly +1. However, I will wait for alternative solutions. And I must reserve 3 days for reading your package. :-)

        – Przemysław Scherwentke
        Mar 31 at 3:10








      • 1





        @PrzemysławScherwentke Thanks. The package idea was mine, but the coding is all Christian's who made it come to life.

        – Steven B. Segletes
        Mar 31 at 3:14






      • 1





        @marmot I am not sure what you mean by "teach" in this context. However, look also at my tabstackengine package, which uses listofitems for parsing. It can digest matrices and remember all the cell content for future use.

        – Steven B. Segletes
        Mar 31 at 3:29






      • 1





        @marmot For example, documentclass{article} usepackage[T1]{fontenc} usepackage{listofitems} setsepchar{\/&} begin{document} readlist*myarray{x11&y12&z13\x21&y22&z_{23}\x31&y32&z33} Row 2, Col 3 = $myarray[2,3]$; tokens detokenizeexpandafterexpandafterexpandafter{myarray[2,3]} end{document}

        – Steven B. Segletes
        Mar 31 at 3:41






      • 1





        @PrzemysławScherwentke listofitems was developed in response to my ill-fated ctan.org/pkg/getargs getargs package. It was a great idea, but just didn't do what needed to be done. Christian T. took that idea and turned it into listofitems.

        – Steven B. Segletes
        Mar 31 at 3:48
















      8














      A listofitems approach. Also, listofitems is available in Plain TeX.



      documentclass{article}
      usepackage{listofitems}
      defvariant#1.{%
      setsepchar{is||has}%
      greadlist*varinput{#1}
      varinput[1] & varinputsep[1] & varinput[2].
      }
      begin{document}
      begin{tabular}{|c|c|c|}
      variant Jim Jones is a fictional character.\
      variant Tim Smith has two brothers.
      end{tabular}
      end{document}


      enter image description here



      Similarly done in plain TeX



      input listofitems
      defvariant#1.{%
      setsepchar{is||has}%
      greadlist*varinput{#1}
      varinput[1] & varinputsep[1] & varinput[2].
      }
      variant Jim Jones is a fictional character.

      variant Tim Smith has two brothers.

      bye





      share|improve this answer
























      • Certainly +1. However, I will wait for alternative solutions. And I must reserve 3 days for reading your package. :-)

        – Przemysław Scherwentke
        Mar 31 at 3:10








      • 1





        @PrzemysławScherwentke Thanks. The package idea was mine, but the coding is all Christian's who made it come to life.

        – Steven B. Segletes
        Mar 31 at 3:14






      • 1





        @marmot I am not sure what you mean by "teach" in this context. However, look also at my tabstackengine package, which uses listofitems for parsing. It can digest matrices and remember all the cell content for future use.

        – Steven B. Segletes
        Mar 31 at 3:29






      • 1





        @marmot For example, documentclass{article} usepackage[T1]{fontenc} usepackage{listofitems} setsepchar{\/&} begin{document} readlist*myarray{x11&y12&z13\x21&y22&z_{23}\x31&y32&z33} Row 2, Col 3 = $myarray[2,3]$; tokens detokenizeexpandafterexpandafterexpandafter{myarray[2,3]} end{document}

        – Steven B. Segletes
        Mar 31 at 3:41






      • 1





        @PrzemysławScherwentke listofitems was developed in response to my ill-fated ctan.org/pkg/getargs getargs package. It was a great idea, but just didn't do what needed to be done. Christian T. took that idea and turned it into listofitems.

        – Steven B. Segletes
        Mar 31 at 3:48














      8












      8








      8







      A listofitems approach. Also, listofitems is available in Plain TeX.



      documentclass{article}
      usepackage{listofitems}
      defvariant#1.{%
      setsepchar{is||has}%
      greadlist*varinput{#1}
      varinput[1] & varinputsep[1] & varinput[2].
      }
      begin{document}
      begin{tabular}{|c|c|c|}
      variant Jim Jones is a fictional character.\
      variant Tim Smith has two brothers.
      end{tabular}
      end{document}


      enter image description here



      Similarly done in plain TeX



      input listofitems
      defvariant#1.{%
      setsepchar{is||has}%
      greadlist*varinput{#1}
      varinput[1] & varinputsep[1] & varinput[2].
      }
      variant Jim Jones is a fictional character.

      variant Tim Smith has two brothers.

      bye





      share|improve this answer













      A listofitems approach. Also, listofitems is available in Plain TeX.



      documentclass{article}
      usepackage{listofitems}
      defvariant#1.{%
      setsepchar{is||has}%
      greadlist*varinput{#1}
      varinput[1] & varinputsep[1] & varinput[2].
      }
      begin{document}
      begin{tabular}{|c|c|c|}
      variant Jim Jones is a fictional character.\
      variant Tim Smith has two brothers.
      end{tabular}
      end{document}


      enter image description here



      Similarly done in plain TeX



      input listofitems
      defvariant#1.{%
      setsepchar{is||has}%
      greadlist*varinput{#1}
      varinput[1] & varinputsep[1] & varinput[2].
      }
      variant Jim Jones is a fictional character.

      variant Tim Smith has two brothers.

      bye






      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Mar 31 at 2:59









      Steven B. SegletesSteven B. Segletes

      160k9205413




      160k9205413













      • Certainly +1. However, I will wait for alternative solutions. And I must reserve 3 days for reading your package. :-)

        – Przemysław Scherwentke
        Mar 31 at 3:10








      • 1





        @PrzemysławScherwentke Thanks. The package idea was mine, but the coding is all Christian's who made it come to life.

        – Steven B. Segletes
        Mar 31 at 3:14






      • 1





        @marmot I am not sure what you mean by "teach" in this context. However, look also at my tabstackengine package, which uses listofitems for parsing. It can digest matrices and remember all the cell content for future use.

        – Steven B. Segletes
        Mar 31 at 3:29






      • 1





        @marmot For example, documentclass{article} usepackage[T1]{fontenc} usepackage{listofitems} setsepchar{\/&} begin{document} readlist*myarray{x11&y12&z13\x21&y22&z_{23}\x31&y32&z33} Row 2, Col 3 = $myarray[2,3]$; tokens detokenizeexpandafterexpandafterexpandafter{myarray[2,3]} end{document}

        – Steven B. Segletes
        Mar 31 at 3:41






      • 1





        @PrzemysławScherwentke listofitems was developed in response to my ill-fated ctan.org/pkg/getargs getargs package. It was a great idea, but just didn't do what needed to be done. Christian T. took that idea and turned it into listofitems.

        – Steven B. Segletes
        Mar 31 at 3:48



















      • Certainly +1. However, I will wait for alternative solutions. And I must reserve 3 days for reading your package. :-)

        – Przemysław Scherwentke
        Mar 31 at 3:10








      • 1





        @PrzemysławScherwentke Thanks. The package idea was mine, but the coding is all Christian's who made it come to life.

        – Steven B. Segletes
        Mar 31 at 3:14






      • 1





        @marmot I am not sure what you mean by "teach" in this context. However, look also at my tabstackengine package, which uses listofitems for parsing. It can digest matrices and remember all the cell content for future use.

        – Steven B. Segletes
        Mar 31 at 3:29






      • 1





        @marmot For example, documentclass{article} usepackage[T1]{fontenc} usepackage{listofitems} setsepchar{\/&} begin{document} readlist*myarray{x11&y12&z13\x21&y22&z_{23}\x31&y32&z33} Row 2, Col 3 = $myarray[2,3]$; tokens detokenizeexpandafterexpandafterexpandafter{myarray[2,3]} end{document}

        – Steven B. Segletes
        Mar 31 at 3:41






      • 1





        @PrzemysławScherwentke listofitems was developed in response to my ill-fated ctan.org/pkg/getargs getargs package. It was a great idea, but just didn't do what needed to be done. Christian T. took that idea and turned it into listofitems.

        – Steven B. Segletes
        Mar 31 at 3:48

















      Certainly +1. However, I will wait for alternative solutions. And I must reserve 3 days for reading your package. :-)

      – Przemysław Scherwentke
      Mar 31 at 3:10







      Certainly +1. However, I will wait for alternative solutions. And I must reserve 3 days for reading your package. :-)

      – Przemysław Scherwentke
      Mar 31 at 3:10






      1




      1





      @PrzemysławScherwentke Thanks. The package idea was mine, but the coding is all Christian's who made it come to life.

      – Steven B. Segletes
      Mar 31 at 3:14





      @PrzemysławScherwentke Thanks. The package idea was mine, but the coding is all Christian's who made it come to life.

      – Steven B. Segletes
      Mar 31 at 3:14




      1




      1





      @marmot I am not sure what you mean by "teach" in this context. However, look also at my tabstackengine package, which uses listofitems for parsing. It can digest matrices and remember all the cell content for future use.

      – Steven B. Segletes
      Mar 31 at 3:29





      @marmot I am not sure what you mean by "teach" in this context. However, look also at my tabstackengine package, which uses listofitems for parsing. It can digest matrices and remember all the cell content for future use.

      – Steven B. Segletes
      Mar 31 at 3:29




      1




      1





      @marmot For example, documentclass{article} usepackage[T1]{fontenc} usepackage{listofitems} setsepchar{\/&} begin{document} readlist*myarray{x11&y12&z13\x21&y22&z_{23}\x31&y32&z33} Row 2, Col 3 = $myarray[2,3]$; tokens detokenizeexpandafterexpandafterexpandafter{myarray[2,3]} end{document}

      – Steven B. Segletes
      Mar 31 at 3:41





      @marmot For example, documentclass{article} usepackage[T1]{fontenc} usepackage{listofitems} setsepchar{\/&} begin{document} readlist*myarray{x11&y12&z13\x21&y22&z_{23}\x31&y32&z33} Row 2, Col 3 = $myarray[2,3]$; tokens detokenizeexpandafterexpandafterexpandafter{myarray[2,3]} end{document}

      – Steven B. Segletes
      Mar 31 at 3:41




      1




      1





      @PrzemysławScherwentke listofitems was developed in response to my ill-fated ctan.org/pkg/getargs getargs package. It was a great idea, but just didn't do what needed to be done. Christian T. took that idea and turned it into listofitems.

      – Steven B. Segletes
      Mar 31 at 3:48





      @PrzemysławScherwentke listofitems was developed in response to my ill-fated ctan.org/pkg/getargs getargs package. It was a great idea, but just didn't do what needed to be done. Christian T. took that idea and turned it into listofitems.

      – Steven B. Segletes
      Mar 31 at 3:48











      3














      The replacestrings macro from OPmac can be used:



      %from OPmac code:
      bgroup catcode`!=3 catcode`?=3
      gdefreplacestrings#1#2{longdefreplacestringsA##1#1{deftmpb{##1}replacestringsB}%
      longdefreplacestringsB##1#1{ifx!##1relax elseaddtotmpb{#2##1}%
      expandafterreplacestringsBfi}% improved version <May 2016> inspired
      expandafterreplacestringsAtmpb?#1!#1%
      longdefreplacestringsA##1?{deftmpb{##1}}expandafterreplacestringsAtmpb
      }
      egroup
      longdefaddto#1#2{expandafterdefexpandafter#1expandafter{#1#2}}

      %variant definition:
      defvariant #1.{deftmpb{#1}%
      replacestrings{ is }{ tabsep is tabsep }%
      replacestrings{ has }{ tabsep has tabsep }%
      tmpb
      }
      deftabsep{&}

      %% test:
      halign{#hfilvrulestrut &#hfilvrule &# hfilcr
      %
      variant Jim Jones is a fictional character. cr
      variant Tim Smith has two brothers. cr
      }

      end





      share|improve this answer




























        3














        The replacestrings macro from OPmac can be used:



        %from OPmac code:
        bgroup catcode`!=3 catcode`?=3
        gdefreplacestrings#1#2{longdefreplacestringsA##1#1{deftmpb{##1}replacestringsB}%
        longdefreplacestringsB##1#1{ifx!##1relax elseaddtotmpb{#2##1}%
        expandafterreplacestringsBfi}% improved version <May 2016> inspired
        expandafterreplacestringsAtmpb?#1!#1%
        longdefreplacestringsA##1?{deftmpb{##1}}expandafterreplacestringsAtmpb
        }
        egroup
        longdefaddto#1#2{expandafterdefexpandafter#1expandafter{#1#2}}

        %variant definition:
        defvariant #1.{deftmpb{#1}%
        replacestrings{ is }{ tabsep is tabsep }%
        replacestrings{ has }{ tabsep has tabsep }%
        tmpb
        }
        deftabsep{&}

        %% test:
        halign{#hfilvrulestrut &#hfilvrule &# hfilcr
        %
        variant Jim Jones is a fictional character. cr
        variant Tim Smith has two brothers. cr
        }

        end





        share|improve this answer


























          3












          3








          3







          The replacestrings macro from OPmac can be used:



          %from OPmac code:
          bgroup catcode`!=3 catcode`?=3
          gdefreplacestrings#1#2{longdefreplacestringsA##1#1{deftmpb{##1}replacestringsB}%
          longdefreplacestringsB##1#1{ifx!##1relax elseaddtotmpb{#2##1}%
          expandafterreplacestringsBfi}% improved version <May 2016> inspired
          expandafterreplacestringsAtmpb?#1!#1%
          longdefreplacestringsA##1?{deftmpb{##1}}expandafterreplacestringsAtmpb
          }
          egroup
          longdefaddto#1#2{expandafterdefexpandafter#1expandafter{#1#2}}

          %variant definition:
          defvariant #1.{deftmpb{#1}%
          replacestrings{ is }{ tabsep is tabsep }%
          replacestrings{ has }{ tabsep has tabsep }%
          tmpb
          }
          deftabsep{&}

          %% test:
          halign{#hfilvrulestrut &#hfilvrule &# hfilcr
          %
          variant Jim Jones is a fictional character. cr
          variant Tim Smith has two brothers. cr
          }

          end





          share|improve this answer













          The replacestrings macro from OPmac can be used:



          %from OPmac code:
          bgroup catcode`!=3 catcode`?=3
          gdefreplacestrings#1#2{longdefreplacestringsA##1#1{deftmpb{##1}replacestringsB}%
          longdefreplacestringsB##1#1{ifx!##1relax elseaddtotmpb{#2##1}%
          expandafterreplacestringsBfi}% improved version <May 2016> inspired
          expandafterreplacestringsAtmpb?#1!#1%
          longdefreplacestringsA##1?{deftmpb{##1}}expandafterreplacestringsAtmpb
          }
          egroup
          longdefaddto#1#2{expandafterdefexpandafter#1expandafter{#1#2}}

          %variant definition:
          defvariant #1.{deftmpb{#1}%
          replacestrings{ is }{ tabsep is tabsep }%
          replacestrings{ has }{ tabsep has tabsep }%
          tmpb
          }
          deftabsep{&}

          %% test:
          halign{#hfilvrulestrut &#hfilvrule &# hfilcr
          %
          variant Jim Jones is a fictional character. cr
          variant Tim Smith has two brothers. cr
          }

          end






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered yesterday









          wipetwipet

          35.4k4983




          35.4k4983























              2














              With expl3, of course. ;-)



              input expl3-generic

              ExplSyntaxOn

              cs_new_protected:Npn 3 #1.
              {
              tl_set:Nx l_tmpa_tl { tl_trim_spaces:n { #1 } }
              regex_replace_once:nnN { s*(is|has)s* } { cT& 1 cT& } l_tmpa_tl
              l_tmpa_tl. cr
              }

              ExplSyntaxOff

              halign{#hfil& hfil#hfil &# hfilcr
              3 Jim Jones is a fictional character and is funny.
              3 Tim Smith has two brothers.
              }

              bye


              enter image description here






              share|improve this answer




























                2














                With expl3, of course. ;-)



                input expl3-generic

                ExplSyntaxOn

                cs_new_protected:Npn 3 #1.
                {
                tl_set:Nx l_tmpa_tl { tl_trim_spaces:n { #1 } }
                regex_replace_once:nnN { s*(is|has)s* } { cT& 1 cT& } l_tmpa_tl
                l_tmpa_tl. cr
                }

                ExplSyntaxOff

                halign{#hfil& hfil#hfil &# hfilcr
                3 Jim Jones is a fictional character and is funny.
                3 Tim Smith has two brothers.
                }

                bye


                enter image description here






                share|improve this answer


























                  2












                  2








                  2







                  With expl3, of course. ;-)



                  input expl3-generic

                  ExplSyntaxOn

                  cs_new_protected:Npn 3 #1.
                  {
                  tl_set:Nx l_tmpa_tl { tl_trim_spaces:n { #1 } }
                  regex_replace_once:nnN { s*(is|has)s* } { cT& 1 cT& } l_tmpa_tl
                  l_tmpa_tl. cr
                  }

                  ExplSyntaxOff

                  halign{#hfil& hfil#hfil &# hfilcr
                  3 Jim Jones is a fictional character and is funny.
                  3 Tim Smith has two brothers.
                  }

                  bye


                  enter image description here






                  share|improve this answer













                  With expl3, of course. ;-)



                  input expl3-generic

                  ExplSyntaxOn

                  cs_new_protected:Npn 3 #1.
                  {
                  tl_set:Nx l_tmpa_tl { tl_trim_spaces:n { #1 } }
                  regex_replace_once:nnN { s*(is|has)s* } { cT& 1 cT& } l_tmpa_tl
                  l_tmpa_tl. cr
                  }

                  ExplSyntaxOff

                  halign{#hfil& hfil#hfil &# hfilcr
                  3 Jim Jones is a fictional character and is funny.
                  3 Tim Smith has two brothers.
                  }

                  bye


                  enter image description here







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered yesterday









                  egregegreg

                  731k8819293246




                  731k8819293246






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f482357%2fhow-to-write-a-definition-with-variants%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      How did Captain America manage to do this?

                      迪纳利

                      南乌拉尔铁路局