Make soul and texttt work together

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite












I was trying to redefine texttt command to make it have background color using package soul. But it seems that it is harder than I thought.



My initial code is



documentclassarticle
usepackagexcolor, soul
colorletmycolorred!30
sethlcolormycolor

letoldtexttttexttt
renewcommandtexttt[1]
hloldtexttt#1


begindocument

textttcan we highlight

enddocument


But it won't run, the error message is:




Argument of texttt has an extra }.




I searched and found this post. The post suggests to use soulregister command. So I add the following line before begindocument:



soulregistertexttt1


But the error persists. I also found this post, which further suggests to use DeclareRobustCommand. Now my code is



documentclassarticle
usepackagexcolor, soul
colorletmycolorred!30
sethlcolormycolor

letoldtexttttexttt
% renewcommandtexttt[1]
% hloldtexttt#1
%

DeclareRobustCommandtexttt[1]
hloldtexttt#1

soulregistertexttt1

begindocument

textttcan we highlight

enddocument


But it doesn't work. The error message is




TeX capacity exceeded, sorry [grouping levels=255]




It seems like rabbit hole of issues. Can you point out what has gone wrong? How to fix this seemingly simple problem?



Edit:



I am using Pandoc to convert Markdown file to PDF. The underlying LaTeX command for Markdown inline code is texttt. But there is no background color. That is why I want to combine soul and texttt.



I have tried the solution of @egreg and @daleif. They both work for standard alone tex code.



documentclassarticle
usepackagexcolor, soul

colorletmycolorred!30
sethlcolormycolor

letoldtexttttexttt

% renewcommandtexttt[1]
% ttfamilyhl#1
%

DeclareRobustCommandtexttt[1]%
hlttfamily#1%


begindocument

textttcan we highlight

enddocument


But if I put it in a file head.tex and compile Markdown to PDF, there are still errors. The content of head.tex is:



usepackagexcolor, soul

colorletmycolorred!30
sethlcolormycolor

letoldtexttttexttt
DeclareRobustCommandtexttt[1]%
hlttfamily#1%



Content of test.md is



`some inline words`


If I try to generate PDF using the new header:



pandoc -H head.tex -s test.md -o test.pdf


there occurs another error:




Package soul Error: Reconstruction failed.











share|improve this question



























    up vote
    3
    down vote

    favorite












    I was trying to redefine texttt command to make it have background color using package soul. But it seems that it is harder than I thought.



    My initial code is



    documentclassarticle
    usepackagexcolor, soul
    colorletmycolorred!30
    sethlcolormycolor

    letoldtexttttexttt
    renewcommandtexttt[1]
    hloldtexttt#1


    begindocument

    textttcan we highlight

    enddocument


    But it won't run, the error message is:




    Argument of texttt has an extra }.




    I searched and found this post. The post suggests to use soulregister command. So I add the following line before begindocument:



    soulregistertexttt1


    But the error persists. I also found this post, which further suggests to use DeclareRobustCommand. Now my code is



    documentclassarticle
    usepackagexcolor, soul
    colorletmycolorred!30
    sethlcolormycolor

    letoldtexttttexttt
    % renewcommandtexttt[1]
    % hloldtexttt#1
    %

    DeclareRobustCommandtexttt[1]
    hloldtexttt#1

    soulregistertexttt1

    begindocument

    textttcan we highlight

    enddocument


    But it doesn't work. The error message is




    TeX capacity exceeded, sorry [grouping levels=255]




    It seems like rabbit hole of issues. Can you point out what has gone wrong? How to fix this seemingly simple problem?



    Edit:



    I am using Pandoc to convert Markdown file to PDF. The underlying LaTeX command for Markdown inline code is texttt. But there is no background color. That is why I want to combine soul and texttt.



    I have tried the solution of @egreg and @daleif. They both work for standard alone tex code.



    documentclassarticle
    usepackagexcolor, soul

    colorletmycolorred!30
    sethlcolormycolor

    letoldtexttttexttt

    % renewcommandtexttt[1]
    % ttfamilyhl#1
    %

    DeclareRobustCommandtexttt[1]%
    hlttfamily#1%


    begindocument

    textttcan we highlight

    enddocument


    But if I put it in a file head.tex and compile Markdown to PDF, there are still errors. The content of head.tex is:



    usepackagexcolor, soul

    colorletmycolorred!30
    sethlcolormycolor

    letoldtexttttexttt
    DeclareRobustCommandtexttt[1]%
    hlttfamily#1%



    Content of test.md is



    `some inline words`


    If I try to generate PDF using the new header:



    pandoc -H head.tex -s test.md -o test.pdf


    there occurs another error:




    Package soul Error: Reconstruction failed.











    share|improve this question

























      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      I was trying to redefine texttt command to make it have background color using package soul. But it seems that it is harder than I thought.



      My initial code is



      documentclassarticle
      usepackagexcolor, soul
      colorletmycolorred!30
      sethlcolormycolor

      letoldtexttttexttt
      renewcommandtexttt[1]
      hloldtexttt#1


      begindocument

      textttcan we highlight

      enddocument


      But it won't run, the error message is:




      Argument of texttt has an extra }.




      I searched and found this post. The post suggests to use soulregister command. So I add the following line before begindocument:



      soulregistertexttt1


      But the error persists. I also found this post, which further suggests to use DeclareRobustCommand. Now my code is



      documentclassarticle
      usepackagexcolor, soul
      colorletmycolorred!30
      sethlcolormycolor

      letoldtexttttexttt
      % renewcommandtexttt[1]
      % hloldtexttt#1
      %

      DeclareRobustCommandtexttt[1]
      hloldtexttt#1

      soulregistertexttt1

      begindocument

      textttcan we highlight

      enddocument


      But it doesn't work. The error message is




      TeX capacity exceeded, sorry [grouping levels=255]




      It seems like rabbit hole of issues. Can you point out what has gone wrong? How to fix this seemingly simple problem?



      Edit:



      I am using Pandoc to convert Markdown file to PDF. The underlying LaTeX command for Markdown inline code is texttt. But there is no background color. That is why I want to combine soul and texttt.



      I have tried the solution of @egreg and @daleif. They both work for standard alone tex code.



      documentclassarticle
      usepackagexcolor, soul

      colorletmycolorred!30
      sethlcolormycolor

      letoldtexttttexttt

      % renewcommandtexttt[1]
      % ttfamilyhl#1
      %

      DeclareRobustCommandtexttt[1]%
      hlttfamily#1%


      begindocument

      textttcan we highlight

      enddocument


      But if I put it in a file head.tex and compile Markdown to PDF, there are still errors. The content of head.tex is:



      usepackagexcolor, soul

      colorletmycolorred!30
      sethlcolormycolor

      letoldtexttttexttt
      DeclareRobustCommandtexttt[1]%
      hlttfamily#1%



      Content of test.md is



      `some inline words`


      If I try to generate PDF using the new header:



      pandoc -H head.tex -s test.md -o test.pdf


      there occurs another error:




      Package soul Error: Reconstruction failed.











      share|improve this question















      I was trying to redefine texttt command to make it have background color using package soul. But it seems that it is harder than I thought.



      My initial code is



      documentclassarticle
      usepackagexcolor, soul
      colorletmycolorred!30
      sethlcolormycolor

      letoldtexttttexttt
      renewcommandtexttt[1]
      hloldtexttt#1


      begindocument

      textttcan we highlight

      enddocument


      But it won't run, the error message is:




      Argument of texttt has an extra }.




      I searched and found this post. The post suggests to use soulregister command. So I add the following line before begindocument:



      soulregistertexttt1


      But the error persists. I also found this post, which further suggests to use DeclareRobustCommand. Now my code is



      documentclassarticle
      usepackagexcolor, soul
      colorletmycolorred!30
      sethlcolormycolor

      letoldtexttttexttt
      % renewcommandtexttt[1]
      % hloldtexttt#1
      %

      DeclareRobustCommandtexttt[1]
      hloldtexttt#1

      soulregistertexttt1

      begindocument

      textttcan we highlight

      enddocument


      But it doesn't work. The error message is




      TeX capacity exceeded, sorry [grouping levels=255]




      It seems like rabbit hole of issues. Can you point out what has gone wrong? How to fix this seemingly simple problem?



      Edit:



      I am using Pandoc to convert Markdown file to PDF. The underlying LaTeX command for Markdown inline code is texttt. But there is no background color. That is why I want to combine soul and texttt.



      I have tried the solution of @egreg and @daleif. They both work for standard alone tex code.



      documentclassarticle
      usepackagexcolor, soul

      colorletmycolorred!30
      sethlcolormycolor

      letoldtexttttexttt

      % renewcommandtexttt[1]
      % ttfamilyhl#1
      %

      DeclareRobustCommandtexttt[1]%
      hlttfamily#1%


      begindocument

      textttcan we highlight

      enddocument


      But if I put it in a file head.tex and compile Markdown to PDF, there are still errors. The content of head.tex is:



      usepackagexcolor, soul

      colorletmycolorred!30
      sethlcolormycolor

      letoldtexttttexttt
      DeclareRobustCommandtexttt[1]%
      hlttfamily#1%



      Content of test.md is



      `some inline words`


      If I try to generate PDF using the new header:



      pandoc -H head.tex -s test.md -o test.pdf


      there occurs another error:




      Package soul Error: Reconstruction failed.








      typewriter soul






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Sep 4 at 9:17

























      asked Sep 4 at 8:22









      jdhao

      334114




      334114




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          5
          down vote













          The soul macros are rather special, it works on a macro level this cannot handle that the contents has "macros" in it.



          I would not overload texttt like that, make a special macro for it.



          BTW: This works ttfamilyhl#1






          share|improve this answer



























            up vote
            1
            down vote













            The working of texttt is essentially absorbing its argument and issuing ttfamily.



            documentclassarticle
            usepackagexcolor, soul

            colorletmycolorred!30
            sethlcolormycolor

            DeclareRobustCommandtexttt[1]%
            hlttfamily#1%


            begindocument

            textttcan we highlight

            enddocument


            enter image description here



            On the other hand, it would be better to use a different command:



            documentclassarticle
            usepackagexcolor, soul

            colorletmycolorred!30
            sethlcolormycolor

            DeclareRobustCommandhltt[1]%
            hlttfamily#1%


            begindocument

            hlttcan we highlight

            enddocument


            Don't forget to protect the end-of-lines.






            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',
              convertImagesToLinks: false,
              noModals: false,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              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%2f449224%2fmake-soul-and-texttt-work-together%23new-answer', 'question_page');

              );

              Post as a guest






























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              5
              down vote













              The soul macros are rather special, it works on a macro level this cannot handle that the contents has "macros" in it.



              I would not overload texttt like that, make a special macro for it.



              BTW: This works ttfamilyhl#1






              share|improve this answer
























                up vote
                5
                down vote













                The soul macros are rather special, it works on a macro level this cannot handle that the contents has "macros" in it.



                I would not overload texttt like that, make a special macro for it.



                BTW: This works ttfamilyhl#1






                share|improve this answer






















                  up vote
                  5
                  down vote










                  up vote
                  5
                  down vote









                  The soul macros are rather special, it works on a macro level this cannot handle that the contents has "macros" in it.



                  I would not overload texttt like that, make a special macro for it.



                  BTW: This works ttfamilyhl#1






                  share|improve this answer












                  The soul macros are rather special, it works on a macro level this cannot handle that the contents has "macros" in it.



                  I would not overload texttt like that, make a special macro for it.



                  BTW: This works ttfamilyhl#1







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Sep 4 at 8:38









                  daleif

                  31.3k247108




                  31.3k247108




















                      up vote
                      1
                      down vote













                      The working of texttt is essentially absorbing its argument and issuing ttfamily.



                      documentclassarticle
                      usepackagexcolor, soul

                      colorletmycolorred!30
                      sethlcolormycolor

                      DeclareRobustCommandtexttt[1]%
                      hlttfamily#1%


                      begindocument

                      textttcan we highlight

                      enddocument


                      enter image description here



                      On the other hand, it would be better to use a different command:



                      documentclassarticle
                      usepackagexcolor, soul

                      colorletmycolorred!30
                      sethlcolormycolor

                      DeclareRobustCommandhltt[1]%
                      hlttfamily#1%


                      begindocument

                      hlttcan we highlight

                      enddocument


                      Don't forget to protect the end-of-lines.






                      share|improve this answer
























                        up vote
                        1
                        down vote













                        The working of texttt is essentially absorbing its argument and issuing ttfamily.



                        documentclassarticle
                        usepackagexcolor, soul

                        colorletmycolorred!30
                        sethlcolormycolor

                        DeclareRobustCommandtexttt[1]%
                        hlttfamily#1%


                        begindocument

                        textttcan we highlight

                        enddocument


                        enter image description here



                        On the other hand, it would be better to use a different command:



                        documentclassarticle
                        usepackagexcolor, soul

                        colorletmycolorred!30
                        sethlcolormycolor

                        DeclareRobustCommandhltt[1]%
                        hlttfamily#1%


                        begindocument

                        hlttcan we highlight

                        enddocument


                        Don't forget to protect the end-of-lines.






                        share|improve this answer






















                          up vote
                          1
                          down vote










                          up vote
                          1
                          down vote









                          The working of texttt is essentially absorbing its argument and issuing ttfamily.



                          documentclassarticle
                          usepackagexcolor, soul

                          colorletmycolorred!30
                          sethlcolormycolor

                          DeclareRobustCommandtexttt[1]%
                          hlttfamily#1%


                          begindocument

                          textttcan we highlight

                          enddocument


                          enter image description here



                          On the other hand, it would be better to use a different command:



                          documentclassarticle
                          usepackagexcolor, soul

                          colorletmycolorred!30
                          sethlcolormycolor

                          DeclareRobustCommandhltt[1]%
                          hlttfamily#1%


                          begindocument

                          hlttcan we highlight

                          enddocument


                          Don't forget to protect the end-of-lines.






                          share|improve this answer












                          The working of texttt is essentially absorbing its argument and issuing ttfamily.



                          documentclassarticle
                          usepackagexcolor, soul

                          colorletmycolorred!30
                          sethlcolormycolor

                          DeclareRobustCommandtexttt[1]%
                          hlttfamily#1%


                          begindocument

                          textttcan we highlight

                          enddocument


                          enter image description here



                          On the other hand, it would be better to use a different command:



                          documentclassarticle
                          usepackagexcolor, soul

                          colorletmycolorred!30
                          sethlcolormycolor

                          DeclareRobustCommandhltt[1]%
                          hlttfamily#1%


                          begindocument

                          hlttcan we highlight

                          enddocument


                          Don't forget to protect the end-of-lines.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Sep 4 at 8:47









                          egreg

                          682k8318183064




                          682k8318183064



























                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f449224%2fmake-soul-and-texttt-work-together%23new-answer', 'question_page');

                              );

                              Post as a guest













































































                              這個網誌中的熱門文章

                              How to combine Bézier curves to a surface?

                              Mutual Information Always Non-negative

                              Why am i infinitely getting the same tweet with the Twitter Search API?