How to wrap an hyperlink generated with a new command with Tex4ht?












1















I'm defining a new command to generate achromatic hyperlinks as follows:



newcommand{CNameRef}[1]{{hypersetup{hidelinks}nameref{#1}}}


It works well with the PDF output however the HTML version of the link is rendered as a normal link. Given this LaTeX input:



A named link to Section~nameref{subsubsec:abney-effect}.

An achromatic named link to Section~CNameRef{subsubsec:abney-effect}.


The generated HTML is as follows:



<p class="noindent">A named link to Section&nbsp;<a href="AdvancedColorimetry.html#x19-590002.5.3">Abney
Effect</a>.</p>
<p class="noindent">An achromatic named link to
Section&nbsp;<a href="AdvancedColorimetry.html#x19-590002.5.3">Abney
Effect</a>.</p>


I would like to be able to wrap the hyperlink with a <span> tag for example.










share|improve this question



























    1















    I'm defining a new command to generate achromatic hyperlinks as follows:



    newcommand{CNameRef}[1]{{hypersetup{hidelinks}nameref{#1}}}


    It works well with the PDF output however the HTML version of the link is rendered as a normal link. Given this LaTeX input:



    A named link to Section~nameref{subsubsec:abney-effect}.

    An achromatic named link to Section~CNameRef{subsubsec:abney-effect}.


    The generated HTML is as follows:



    <p class="noindent">A named link to Section&nbsp;<a href="AdvancedColorimetry.html#x19-590002.5.3">Abney
    Effect</a>.</p>
    <p class="noindent">An achromatic named link to
    Section&nbsp;<a href="AdvancedColorimetry.html#x19-590002.5.3">Abney
    Effect</a>.</p>


    I would like to be able to wrap the hyperlink with a <span> tag for example.










    share|improve this question

























      1












      1








      1








      I'm defining a new command to generate achromatic hyperlinks as follows:



      newcommand{CNameRef}[1]{{hypersetup{hidelinks}nameref{#1}}}


      It works well with the PDF output however the HTML version of the link is rendered as a normal link. Given this LaTeX input:



      A named link to Section~nameref{subsubsec:abney-effect}.

      An achromatic named link to Section~CNameRef{subsubsec:abney-effect}.


      The generated HTML is as follows:



      <p class="noindent">A named link to Section&nbsp;<a href="AdvancedColorimetry.html#x19-590002.5.3">Abney
      Effect</a>.</p>
      <p class="noindent">An achromatic named link to
      Section&nbsp;<a href="AdvancedColorimetry.html#x19-590002.5.3">Abney
      Effect</a>.</p>


      I would like to be able to wrap the hyperlink with a <span> tag for example.










      share|improve this question














      I'm defining a new command to generate achromatic hyperlinks as follows:



      newcommand{CNameRef}[1]{{hypersetup{hidelinks}nameref{#1}}}


      It works well with the PDF output however the HTML version of the link is rendered as a normal link. Given this LaTeX input:



      A named link to Section~nameref{subsubsec:abney-effect}.

      An achromatic named link to Section~CNameRef{subsubsec:abney-effect}.


      The generated HTML is as follows:



      <p class="noindent">A named link to Section&nbsp;<a href="AdvancedColorimetry.html#x19-590002.5.3">Abney
      Effect</a>.</p>
      <p class="noindent">An achromatic named link to
      Section&nbsp;<a href="AdvancedColorimetry.html#x19-590002.5.3">Abney
      Effect</a>.</p>


      I would like to be able to wrap the hyperlink with a <span> tag for example.







      hyperref tex4ht






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 24 at 19:45









      Kel SolaarKel Solaar

      1204




      1204






















          1 Answer
          1






          active

          oldest

          votes


















          2














          You need to redefine the CNameRef when tex4ht is running to output the <span> element. Easiest way to do that is to move the command definition to a package, say mycommands.sty:



          ProvidesPackage{mycommands}
          RequirePackage{hyperref}
          newcommand{CNameRef}[1]{{hypersetup{hidelinks}nameref{#1}}}
          endinput


          This way we can provide a configuration file for tex4ht, mycommands.4ht:



          NewConfigure{CNameRef}{2}
          def:temp#1{a:CNameRefo:CNameRef:{#1}b:CNameRef}
          HLetCNameRef:temp

          Configure{CNameRef}{HCode{<span class="CNameRef">}}{HCode{</span>}}

          Hinput{mycommands}


          What's going on here? With the NewConfigure command, so called hooks are defined. These will be later used to insert the HTML tags. The second parameter is the name of the hook and the last one is number of generated hooks. Because we want to insert tags before and after the command, we need two hooks. These hooks are special commands, named as a:CNameRef and b:CNameRef. The : character can be used as a part of command names in .4ht files.



          The next line defines a temporary command which will be used in place of the original command. The o:CnameRef: command contains the original CNameRef command, it needs to be executed to generate the link. Before and after it are placed the hooks which will insert the HTML code.



          The next line, HLetCNameRef:temp is a variant of the let command, which saves the original form of the first command in a o:CNameRef: macro and replaces it with the temporary command defined in the previous step.



          Finally, Configure{CNameRef}{HCode{<span class="CNameRef">}}{HCode{</span>}} configures the CNameRef hooks with the HTML code.



          It is time for an example now:



          documentclass{article}

          usepackage{mycommands}

          begin{document}
          section{Hello world}label{subsubsec:abney-effect}
          A named link to Section~nameref{subsubsec:abney-effect}.

          An achromatic named link to Section~CNameRef{subsubsec:abney-effect}.
          end{document}


          Here is the generated HTML:



          <h3 class="sectionHead"><span class="titlemark">1   </span> <a 
          id="x1-10001"></a>Hello world</h3>
          <!--l. 7--><p class="noindent" >A named link to Section <a
          href="#x1-10001">Hello world<!--tex4ht:ref: subsubsec:abney-effect --></a>.
          </p><!--l. 9--><p class="indent" > An achromatic named link to Section <span class="CNameRef"><a
          href="#x1-10001">Hello world<!--tex4ht:ref: subsubsec:abney-effect --></a></span>. </p>





          share|improve this answer
























          • Awesome! I really appreciate educational all your answers here are.

            – Kel Solaar
            Jan 24 at 23:33











          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%2f471712%2fhow-to-wrap-an-hyperlink-generated-with-a-new-command-with-tex4ht%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          You need to redefine the CNameRef when tex4ht is running to output the <span> element. Easiest way to do that is to move the command definition to a package, say mycommands.sty:



          ProvidesPackage{mycommands}
          RequirePackage{hyperref}
          newcommand{CNameRef}[1]{{hypersetup{hidelinks}nameref{#1}}}
          endinput


          This way we can provide a configuration file for tex4ht, mycommands.4ht:



          NewConfigure{CNameRef}{2}
          def:temp#1{a:CNameRefo:CNameRef:{#1}b:CNameRef}
          HLetCNameRef:temp

          Configure{CNameRef}{HCode{<span class="CNameRef">}}{HCode{</span>}}

          Hinput{mycommands}


          What's going on here? With the NewConfigure command, so called hooks are defined. These will be later used to insert the HTML tags. The second parameter is the name of the hook and the last one is number of generated hooks. Because we want to insert tags before and after the command, we need two hooks. These hooks are special commands, named as a:CNameRef and b:CNameRef. The : character can be used as a part of command names in .4ht files.



          The next line defines a temporary command which will be used in place of the original command. The o:CnameRef: command contains the original CNameRef command, it needs to be executed to generate the link. Before and after it are placed the hooks which will insert the HTML code.



          The next line, HLetCNameRef:temp is a variant of the let command, which saves the original form of the first command in a o:CNameRef: macro and replaces it with the temporary command defined in the previous step.



          Finally, Configure{CNameRef}{HCode{<span class="CNameRef">}}{HCode{</span>}} configures the CNameRef hooks with the HTML code.



          It is time for an example now:



          documentclass{article}

          usepackage{mycommands}

          begin{document}
          section{Hello world}label{subsubsec:abney-effect}
          A named link to Section~nameref{subsubsec:abney-effect}.

          An achromatic named link to Section~CNameRef{subsubsec:abney-effect}.
          end{document}


          Here is the generated HTML:



          <h3 class="sectionHead"><span class="titlemark">1   </span> <a 
          id="x1-10001"></a>Hello world</h3>
          <!--l. 7--><p class="noindent" >A named link to Section <a
          href="#x1-10001">Hello world<!--tex4ht:ref: subsubsec:abney-effect --></a>.
          </p><!--l. 9--><p class="indent" > An achromatic named link to Section <span class="CNameRef"><a
          href="#x1-10001">Hello world<!--tex4ht:ref: subsubsec:abney-effect --></a></span>. </p>





          share|improve this answer
























          • Awesome! I really appreciate educational all your answers here are.

            – Kel Solaar
            Jan 24 at 23:33
















          2














          You need to redefine the CNameRef when tex4ht is running to output the <span> element. Easiest way to do that is to move the command definition to a package, say mycommands.sty:



          ProvidesPackage{mycommands}
          RequirePackage{hyperref}
          newcommand{CNameRef}[1]{{hypersetup{hidelinks}nameref{#1}}}
          endinput


          This way we can provide a configuration file for tex4ht, mycommands.4ht:



          NewConfigure{CNameRef}{2}
          def:temp#1{a:CNameRefo:CNameRef:{#1}b:CNameRef}
          HLetCNameRef:temp

          Configure{CNameRef}{HCode{<span class="CNameRef">}}{HCode{</span>}}

          Hinput{mycommands}


          What's going on here? With the NewConfigure command, so called hooks are defined. These will be later used to insert the HTML tags. The second parameter is the name of the hook and the last one is number of generated hooks. Because we want to insert tags before and after the command, we need two hooks. These hooks are special commands, named as a:CNameRef and b:CNameRef. The : character can be used as a part of command names in .4ht files.



          The next line defines a temporary command which will be used in place of the original command. The o:CnameRef: command contains the original CNameRef command, it needs to be executed to generate the link. Before and after it are placed the hooks which will insert the HTML code.



          The next line, HLetCNameRef:temp is a variant of the let command, which saves the original form of the first command in a o:CNameRef: macro and replaces it with the temporary command defined in the previous step.



          Finally, Configure{CNameRef}{HCode{<span class="CNameRef">}}{HCode{</span>}} configures the CNameRef hooks with the HTML code.



          It is time for an example now:



          documentclass{article}

          usepackage{mycommands}

          begin{document}
          section{Hello world}label{subsubsec:abney-effect}
          A named link to Section~nameref{subsubsec:abney-effect}.

          An achromatic named link to Section~CNameRef{subsubsec:abney-effect}.
          end{document}


          Here is the generated HTML:



          <h3 class="sectionHead"><span class="titlemark">1   </span> <a 
          id="x1-10001"></a>Hello world</h3>
          <!--l. 7--><p class="noindent" >A named link to Section <a
          href="#x1-10001">Hello world<!--tex4ht:ref: subsubsec:abney-effect --></a>.
          </p><!--l. 9--><p class="indent" > An achromatic named link to Section <span class="CNameRef"><a
          href="#x1-10001">Hello world<!--tex4ht:ref: subsubsec:abney-effect --></a></span>. </p>





          share|improve this answer
























          • Awesome! I really appreciate educational all your answers here are.

            – Kel Solaar
            Jan 24 at 23:33














          2












          2








          2







          You need to redefine the CNameRef when tex4ht is running to output the <span> element. Easiest way to do that is to move the command definition to a package, say mycommands.sty:



          ProvidesPackage{mycommands}
          RequirePackage{hyperref}
          newcommand{CNameRef}[1]{{hypersetup{hidelinks}nameref{#1}}}
          endinput


          This way we can provide a configuration file for tex4ht, mycommands.4ht:



          NewConfigure{CNameRef}{2}
          def:temp#1{a:CNameRefo:CNameRef:{#1}b:CNameRef}
          HLetCNameRef:temp

          Configure{CNameRef}{HCode{<span class="CNameRef">}}{HCode{</span>}}

          Hinput{mycommands}


          What's going on here? With the NewConfigure command, so called hooks are defined. These will be later used to insert the HTML tags. The second parameter is the name of the hook and the last one is number of generated hooks. Because we want to insert tags before and after the command, we need two hooks. These hooks are special commands, named as a:CNameRef and b:CNameRef. The : character can be used as a part of command names in .4ht files.



          The next line defines a temporary command which will be used in place of the original command. The o:CnameRef: command contains the original CNameRef command, it needs to be executed to generate the link. Before and after it are placed the hooks which will insert the HTML code.



          The next line, HLetCNameRef:temp is a variant of the let command, which saves the original form of the first command in a o:CNameRef: macro and replaces it with the temporary command defined in the previous step.



          Finally, Configure{CNameRef}{HCode{<span class="CNameRef">}}{HCode{</span>}} configures the CNameRef hooks with the HTML code.



          It is time for an example now:



          documentclass{article}

          usepackage{mycommands}

          begin{document}
          section{Hello world}label{subsubsec:abney-effect}
          A named link to Section~nameref{subsubsec:abney-effect}.

          An achromatic named link to Section~CNameRef{subsubsec:abney-effect}.
          end{document}


          Here is the generated HTML:



          <h3 class="sectionHead"><span class="titlemark">1   </span> <a 
          id="x1-10001"></a>Hello world</h3>
          <!--l. 7--><p class="noindent" >A named link to Section <a
          href="#x1-10001">Hello world<!--tex4ht:ref: subsubsec:abney-effect --></a>.
          </p><!--l. 9--><p class="indent" > An achromatic named link to Section <span class="CNameRef"><a
          href="#x1-10001">Hello world<!--tex4ht:ref: subsubsec:abney-effect --></a></span>. </p>





          share|improve this answer













          You need to redefine the CNameRef when tex4ht is running to output the <span> element. Easiest way to do that is to move the command definition to a package, say mycommands.sty:



          ProvidesPackage{mycommands}
          RequirePackage{hyperref}
          newcommand{CNameRef}[1]{{hypersetup{hidelinks}nameref{#1}}}
          endinput


          This way we can provide a configuration file for tex4ht, mycommands.4ht:



          NewConfigure{CNameRef}{2}
          def:temp#1{a:CNameRefo:CNameRef:{#1}b:CNameRef}
          HLetCNameRef:temp

          Configure{CNameRef}{HCode{<span class="CNameRef">}}{HCode{</span>}}

          Hinput{mycommands}


          What's going on here? With the NewConfigure command, so called hooks are defined. These will be later used to insert the HTML tags. The second parameter is the name of the hook and the last one is number of generated hooks. Because we want to insert tags before and after the command, we need two hooks. These hooks are special commands, named as a:CNameRef and b:CNameRef. The : character can be used as a part of command names in .4ht files.



          The next line defines a temporary command which will be used in place of the original command. The o:CnameRef: command contains the original CNameRef command, it needs to be executed to generate the link. Before and after it are placed the hooks which will insert the HTML code.



          The next line, HLetCNameRef:temp is a variant of the let command, which saves the original form of the first command in a o:CNameRef: macro and replaces it with the temporary command defined in the previous step.



          Finally, Configure{CNameRef}{HCode{<span class="CNameRef">}}{HCode{</span>}} configures the CNameRef hooks with the HTML code.



          It is time for an example now:



          documentclass{article}

          usepackage{mycommands}

          begin{document}
          section{Hello world}label{subsubsec:abney-effect}
          A named link to Section~nameref{subsubsec:abney-effect}.

          An achromatic named link to Section~CNameRef{subsubsec:abney-effect}.
          end{document}


          Here is the generated HTML:



          <h3 class="sectionHead"><span class="titlemark">1   </span> <a 
          id="x1-10001"></a>Hello world</h3>
          <!--l. 7--><p class="noindent" >A named link to Section <a
          href="#x1-10001">Hello world<!--tex4ht:ref: subsubsec:abney-effect --></a>.
          </p><!--l. 9--><p class="indent" > An achromatic named link to Section <span class="CNameRef"><a
          href="#x1-10001">Hello world<!--tex4ht:ref: subsubsec:abney-effect --></a></span>. </p>






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 24 at 20:29









          michal.h21michal.h21

          31k447104




          31k447104













          • Awesome! I really appreciate educational all your answers here are.

            – Kel Solaar
            Jan 24 at 23:33



















          • Awesome! I really appreciate educational all your answers here are.

            – Kel Solaar
            Jan 24 at 23:33

















          Awesome! I really appreciate educational all your answers here are.

          – Kel Solaar
          Jan 24 at 23:33





          Awesome! I really appreciate educational all your answers here are.

          – Kel Solaar
          Jan 24 at 23:33


















          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%2f471712%2fhow-to-wrap-an-hyperlink-generated-with-a-new-command-with-tex4ht%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

          mysqli_query(): Empty query in /home/lucindabrummitt/public_html/blog/wp-includes/wp-db.php on line 1924

          How to change which sound is reproduced for terminal bell?

          Can I use Tabulator js library in my java Spring + Thymeleaf project?