Inline environment shortcut (like $blah$)












0















I want to be able to format code with a monospaced font. Right now I'm using texttt{} but it's kind of a pain to keep typing that everywhere. Is there any way to use a shortcut instead? For example, for math, you can wrap it in $. So, for my situation, I'd like to be able to write something like:



`const WIDTH = 5`



and have it turn into:
const WIDTH = 5



I've tried looking for shortcuts (which gave me a bunch of editor stuff), new commands (which told me how to define a new backslash command) and macros (which I didn't really understand but aren't what I want).










share|improve this question























  • Almost all editors have this feature. You can create a shortcut for texttt{} (like ctrl+i for textit{}). What editor do you use?

    – Sigur
    Feb 16 at 18:06











  • Is an editor the only way to do this? I was really hoping for something lower level, so to speak.

    – Jharod
    Feb 16 at 18:08











  • Lets wait experts. I think you have to change the catcode of the `.

    – Sigur
    Feb 16 at 18:10






  • 1





    Do you want just texttt or do you need a real verbatim environment? (e.g. will the content contain characters that are normally escaped in TeX? If so, perhaps you want to use fancyvrb DefineShortVerb{|} which will allow you to write |foo| to get what you want.

    – Alan Munn
    Feb 16 at 18:16


















0















I want to be able to format code with a monospaced font. Right now I'm using texttt{} but it's kind of a pain to keep typing that everywhere. Is there any way to use a shortcut instead? For example, for math, you can wrap it in $. So, for my situation, I'd like to be able to write something like:



`const WIDTH = 5`



and have it turn into:
const WIDTH = 5



I've tried looking for shortcuts (which gave me a bunch of editor stuff), new commands (which told me how to define a new backslash command) and macros (which I didn't really understand but aren't what I want).










share|improve this question























  • Almost all editors have this feature. You can create a shortcut for texttt{} (like ctrl+i for textit{}). What editor do you use?

    – Sigur
    Feb 16 at 18:06











  • Is an editor the only way to do this? I was really hoping for something lower level, so to speak.

    – Jharod
    Feb 16 at 18:08











  • Lets wait experts. I think you have to change the catcode of the `.

    – Sigur
    Feb 16 at 18:10






  • 1





    Do you want just texttt or do you need a real verbatim environment? (e.g. will the content contain characters that are normally escaped in TeX? If so, perhaps you want to use fancyvrb DefineShortVerb{|} which will allow you to write |foo| to get what you want.

    – Alan Munn
    Feb 16 at 18:16
















0












0








0








I want to be able to format code with a monospaced font. Right now I'm using texttt{} but it's kind of a pain to keep typing that everywhere. Is there any way to use a shortcut instead? For example, for math, you can wrap it in $. So, for my situation, I'd like to be able to write something like:



`const WIDTH = 5`



and have it turn into:
const WIDTH = 5



I've tried looking for shortcuts (which gave me a bunch of editor stuff), new commands (which told me how to define a new backslash command) and macros (which I didn't really understand but aren't what I want).










share|improve this question














I want to be able to format code with a monospaced font. Right now I'm using texttt{} but it's kind of a pain to keep typing that everywhere. Is there any way to use a shortcut instead? For example, for math, you can wrap it in $. So, for my situation, I'd like to be able to write something like:



`const WIDTH = 5`



and have it turn into:
const WIDTH = 5



I've tried looking for shortcuts (which gave me a bunch of editor stuff), new commands (which told me how to define a new backslash command) and macros (which I didn't really understand but aren't what I want).







math-mode code






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Feb 16 at 18:02









JharodJharod

31




31













  • Almost all editors have this feature. You can create a shortcut for texttt{} (like ctrl+i for textit{}). What editor do you use?

    – Sigur
    Feb 16 at 18:06











  • Is an editor the only way to do this? I was really hoping for something lower level, so to speak.

    – Jharod
    Feb 16 at 18:08











  • Lets wait experts. I think you have to change the catcode of the `.

    – Sigur
    Feb 16 at 18:10






  • 1





    Do you want just texttt or do you need a real verbatim environment? (e.g. will the content contain characters that are normally escaped in TeX? If so, perhaps you want to use fancyvrb DefineShortVerb{|} which will allow you to write |foo| to get what you want.

    – Alan Munn
    Feb 16 at 18:16





















  • Almost all editors have this feature. You can create a shortcut for texttt{} (like ctrl+i for textit{}). What editor do you use?

    – Sigur
    Feb 16 at 18:06











  • Is an editor the only way to do this? I was really hoping for something lower level, so to speak.

    – Jharod
    Feb 16 at 18:08











  • Lets wait experts. I think you have to change the catcode of the `.

    – Sigur
    Feb 16 at 18:10






  • 1





    Do you want just texttt or do you need a real verbatim environment? (e.g. will the content contain characters that are normally escaped in TeX? If so, perhaps you want to use fancyvrb DefineShortVerb{|} which will allow you to write |foo| to get what you want.

    – Alan Munn
    Feb 16 at 18:16



















Almost all editors have this feature. You can create a shortcut for texttt{} (like ctrl+i for textit{}). What editor do you use?

– Sigur
Feb 16 at 18:06





Almost all editors have this feature. You can create a shortcut for texttt{} (like ctrl+i for textit{}). What editor do you use?

– Sigur
Feb 16 at 18:06













Is an editor the only way to do this? I was really hoping for something lower level, so to speak.

– Jharod
Feb 16 at 18:08





Is an editor the only way to do this? I was really hoping for something lower level, so to speak.

– Jharod
Feb 16 at 18:08













Lets wait experts. I think you have to change the catcode of the `.

– Sigur
Feb 16 at 18:10





Lets wait experts. I think you have to change the catcode of the `.

– Sigur
Feb 16 at 18:10




1




1





Do you want just texttt or do you need a real verbatim environment? (e.g. will the content contain characters that are normally escaped in TeX? If so, perhaps you want to use fancyvrb DefineShortVerb{|} which will allow you to write |foo| to get what you want.

– Alan Munn
Feb 16 at 18:16







Do you want just texttt or do you need a real verbatim environment? (e.g. will the content contain characters that are normally escaped in TeX? If so, perhaps you want to use fancyvrb DefineShortVerb{|} which will allow you to write |foo| to get what you want.

– Alan Munn
Feb 16 at 18:16












3 Answers
3






active

oldest

votes


















3














You can turn | into inline verbatim like doc.sty does:



documentclass{article}

makeatletter
%Shamelessly copied from doc.sty
defMakeShortVerb{%>>>
@ifstar
{def@shortvrbdef{verb*}@MakeShortVerb}%
{def@shortvrbdef{verb}@MakeShortVerb}}%<<<
def@MakeShortVerb#1{%>>>
expandafterifxcsname ccstring#1endcsnamerelax
@shortvrbinfo{Made }{#1}@shortvrbdef
add@special{#1}%
expandafter
xdefcsname ccstring#1endcsname{thecatcode`#1}%
begingroup
catcode`~active lccode`~`#1%
lowercase{%
globalexpandafterlet
csname acstring#1endcsname~%
expandaftergdefexpandafter~expandafter{@shortvrbdef~}}%
endgroup
globalcatcode`#1active
else
@shortvrbinfo@empty{#1 already}{@emptyverb(*)}%
fi}%<<<
defDeleteShortVerb#1{%>>>
expandafterifxcsname ccstring#1endcsnamerelax
@shortvrbinfo@empty{#1 not}{@emptyverb(*)}%
else
@shortvrbinfo{Deleted }{#1 as}{@emptyverb(*)}%
rem@special{#1}%
globalcatcode`#1csname ccstring#1endcsname
global expandafterlet csname ccstring#1endcsname relax
ifnumcatcode`#1=active
begingroup
catcode`~active lccode`~`#1%
lowercase{%
globalexpandafterletexpandafter~%
csname acstring#1endcsname}%
endgroup fi fi}%<<<
def@shortvrbinfo#1#2#3{%>>>
PackageInfo{doc}{%
#1expandafter@gobblestring#2 a short reference
for expandafterstring#3}}%<<<
defadd@special#1{%>>>
rem@special{#1}%
expandaftergdefexpandafterdospecialsexpandafter
{dospecials do #1}%
expandaftergdefexpandafter@sanitizeexpandafter
{@sanitize @makeother #1}}%<<<
defrem@special#1{%>>>
defdo##1{%
ifnum`#1=`##1 else noexpanddonoexpand##1fi}%
xdefdospecials{dospecials}%
begingroup
def@makeother##1{%
ifnum`#1=`##1 else noexpand@makeothernoexpand##1fi}%
xdef@sanitize{@sanitize}%
endgroup}%<<<
AtBeginDocument{MakeShortVerb |}
AtEndDocument{DeleteShortVerb |}
makeatother

begin{document}
|Test|

but also |Test$_{}|
end{document}





share|improve this answer





















  • 2





    Rather than copying all this code, it's probably easier just to load the fancyvrb package which provides a DefineShortVerb macro to do the same thing.

    – Alan Munn
    Feb 16 at 18:18











  • @AlanMunn yes, that would have been better... Do you want to answer or should I edit mine?

    – Skillmon
    Feb 16 at 18:19











  • The idea is the same; I would just edit your answer to do it that way.

    – Alan Munn
    Feb 16 at 18:20











  • I tried fancyvrb but it didn't work. The copy/paste blob works perfectly and I don't mind it since I have a separate preamble.tex file to hide it in. I do have one further question -- the blob is really hard to understand and I'm wondering how to add a highlight to the contents?

    – Jharod
    Feb 16 at 18:21













  • @Jharod The fancyvrb solution should definitely work, and is a much better solution that a ton of copied code you don't understand. If you edit your question to show a non-working fancyvrb example, we could help you with that.

    – Alan Munn
    Feb 16 at 18:22



















3














It looks like you want an inline verbatim environment. The fancyvrb package provides a simple way to do that. Note that, just like the Skillmon's solution, you cannot define the backtick to be the verbatim delimiter with this approach. Alternatively, if you just don't like having to type texttt all the time you could make a shorter replacement macro for it. Here I've used vrb. Notice how the fancyvrb version allows the use of reserved TeX characters without being escaped; the texttt solution does not.



documentclass{article}
usepackage{fancyvrb}
DefineShortVerb{|}
newcommand{vrb}{texttt}
begin{document}

Using the |fancyvrb| |foo|

Using a macro |vrb{foo}| vrb{foo}

end{document}


output of code






share|improve this answer

































    2














    Not really complicated and, differently from other proposed answers, the object can go in the argument to another command.



    Thus something like mbox{`const WIDTH = 5`} will work.



    documentclass{article}

    makeatletter
    % define the active backquote
    begingrouplccode`~=``lowercase{endgroup
    def~#1~{texttt{#1}}%
    }
    % delay activating at begin document
    AtBeginDocument{catcode``=active}
    makeatother

    begin{document}

    This is texttt{const WIDTH = 5}

    This is `const WIDTH = 5`

    end{document}


    Beware it is quite fragile and finding a missing backquote could be difficult. It's simpler if you define some shortcut with your editor.



    enter image description here



    Even more fragile with double back quotes for denoting verbatim mode (however, the double back quotes cannot be used in the argument to another command, just like verb).



    documentclass{article}

    makeatletter
    % define the active backquote
    begingrouplccode`~=``lowercase{endgroup
    defjharodbackquote{@ifnextchar~jharodverbjharodtt}
    defjharodtt#1~{texttt{#1}}
    let~jharodbackquote
    defjharodverb{bgroupcatcode``=2 verb}
    }
    % delay activating at begin document
    AtBeginDocument{catcode``=active}
    makeatother

    begin{document}

    This is mbox{`const WIDTH = 5`}

    This is `const WIDTH = 5`

    This is ``verb{atim}``

    This is `const WIDTH = 5`

    end{document}


    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%2f475230%2finline-environment-shortcut-like-blah%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









      3














      You can turn | into inline verbatim like doc.sty does:



      documentclass{article}

      makeatletter
      %Shamelessly copied from doc.sty
      defMakeShortVerb{%>>>
      @ifstar
      {def@shortvrbdef{verb*}@MakeShortVerb}%
      {def@shortvrbdef{verb}@MakeShortVerb}}%<<<
      def@MakeShortVerb#1{%>>>
      expandafterifxcsname ccstring#1endcsnamerelax
      @shortvrbinfo{Made }{#1}@shortvrbdef
      add@special{#1}%
      expandafter
      xdefcsname ccstring#1endcsname{thecatcode`#1}%
      begingroup
      catcode`~active lccode`~`#1%
      lowercase{%
      globalexpandafterlet
      csname acstring#1endcsname~%
      expandaftergdefexpandafter~expandafter{@shortvrbdef~}}%
      endgroup
      globalcatcode`#1active
      else
      @shortvrbinfo@empty{#1 already}{@emptyverb(*)}%
      fi}%<<<
      defDeleteShortVerb#1{%>>>
      expandafterifxcsname ccstring#1endcsnamerelax
      @shortvrbinfo@empty{#1 not}{@emptyverb(*)}%
      else
      @shortvrbinfo{Deleted }{#1 as}{@emptyverb(*)}%
      rem@special{#1}%
      globalcatcode`#1csname ccstring#1endcsname
      global expandafterlet csname ccstring#1endcsname relax
      ifnumcatcode`#1=active
      begingroup
      catcode`~active lccode`~`#1%
      lowercase{%
      globalexpandafterletexpandafter~%
      csname acstring#1endcsname}%
      endgroup fi fi}%<<<
      def@shortvrbinfo#1#2#3{%>>>
      PackageInfo{doc}{%
      #1expandafter@gobblestring#2 a short reference
      for expandafterstring#3}}%<<<
      defadd@special#1{%>>>
      rem@special{#1}%
      expandaftergdefexpandafterdospecialsexpandafter
      {dospecials do #1}%
      expandaftergdefexpandafter@sanitizeexpandafter
      {@sanitize @makeother #1}}%<<<
      defrem@special#1{%>>>
      defdo##1{%
      ifnum`#1=`##1 else noexpanddonoexpand##1fi}%
      xdefdospecials{dospecials}%
      begingroup
      def@makeother##1{%
      ifnum`#1=`##1 else noexpand@makeothernoexpand##1fi}%
      xdef@sanitize{@sanitize}%
      endgroup}%<<<
      AtBeginDocument{MakeShortVerb |}
      AtEndDocument{DeleteShortVerb |}
      makeatother

      begin{document}
      |Test|

      but also |Test$_{}|
      end{document}





      share|improve this answer





















      • 2





        Rather than copying all this code, it's probably easier just to load the fancyvrb package which provides a DefineShortVerb macro to do the same thing.

        – Alan Munn
        Feb 16 at 18:18











      • @AlanMunn yes, that would have been better... Do you want to answer or should I edit mine?

        – Skillmon
        Feb 16 at 18:19











      • The idea is the same; I would just edit your answer to do it that way.

        – Alan Munn
        Feb 16 at 18:20











      • I tried fancyvrb but it didn't work. The copy/paste blob works perfectly and I don't mind it since I have a separate preamble.tex file to hide it in. I do have one further question -- the blob is really hard to understand and I'm wondering how to add a highlight to the contents?

        – Jharod
        Feb 16 at 18:21













      • @Jharod The fancyvrb solution should definitely work, and is a much better solution that a ton of copied code you don't understand. If you edit your question to show a non-working fancyvrb example, we could help you with that.

        – Alan Munn
        Feb 16 at 18:22
















      3














      You can turn | into inline verbatim like doc.sty does:



      documentclass{article}

      makeatletter
      %Shamelessly copied from doc.sty
      defMakeShortVerb{%>>>
      @ifstar
      {def@shortvrbdef{verb*}@MakeShortVerb}%
      {def@shortvrbdef{verb}@MakeShortVerb}}%<<<
      def@MakeShortVerb#1{%>>>
      expandafterifxcsname ccstring#1endcsnamerelax
      @shortvrbinfo{Made }{#1}@shortvrbdef
      add@special{#1}%
      expandafter
      xdefcsname ccstring#1endcsname{thecatcode`#1}%
      begingroup
      catcode`~active lccode`~`#1%
      lowercase{%
      globalexpandafterlet
      csname acstring#1endcsname~%
      expandaftergdefexpandafter~expandafter{@shortvrbdef~}}%
      endgroup
      globalcatcode`#1active
      else
      @shortvrbinfo@empty{#1 already}{@emptyverb(*)}%
      fi}%<<<
      defDeleteShortVerb#1{%>>>
      expandafterifxcsname ccstring#1endcsnamerelax
      @shortvrbinfo@empty{#1 not}{@emptyverb(*)}%
      else
      @shortvrbinfo{Deleted }{#1 as}{@emptyverb(*)}%
      rem@special{#1}%
      globalcatcode`#1csname ccstring#1endcsname
      global expandafterlet csname ccstring#1endcsname relax
      ifnumcatcode`#1=active
      begingroup
      catcode`~active lccode`~`#1%
      lowercase{%
      globalexpandafterletexpandafter~%
      csname acstring#1endcsname}%
      endgroup fi fi}%<<<
      def@shortvrbinfo#1#2#3{%>>>
      PackageInfo{doc}{%
      #1expandafter@gobblestring#2 a short reference
      for expandafterstring#3}}%<<<
      defadd@special#1{%>>>
      rem@special{#1}%
      expandaftergdefexpandafterdospecialsexpandafter
      {dospecials do #1}%
      expandaftergdefexpandafter@sanitizeexpandafter
      {@sanitize @makeother #1}}%<<<
      defrem@special#1{%>>>
      defdo##1{%
      ifnum`#1=`##1 else noexpanddonoexpand##1fi}%
      xdefdospecials{dospecials}%
      begingroup
      def@makeother##1{%
      ifnum`#1=`##1 else noexpand@makeothernoexpand##1fi}%
      xdef@sanitize{@sanitize}%
      endgroup}%<<<
      AtBeginDocument{MakeShortVerb |}
      AtEndDocument{DeleteShortVerb |}
      makeatother

      begin{document}
      |Test|

      but also |Test$_{}|
      end{document}





      share|improve this answer





















      • 2





        Rather than copying all this code, it's probably easier just to load the fancyvrb package which provides a DefineShortVerb macro to do the same thing.

        – Alan Munn
        Feb 16 at 18:18











      • @AlanMunn yes, that would have been better... Do you want to answer or should I edit mine?

        – Skillmon
        Feb 16 at 18:19











      • The idea is the same; I would just edit your answer to do it that way.

        – Alan Munn
        Feb 16 at 18:20











      • I tried fancyvrb but it didn't work. The copy/paste blob works perfectly and I don't mind it since I have a separate preamble.tex file to hide it in. I do have one further question -- the blob is really hard to understand and I'm wondering how to add a highlight to the contents?

        – Jharod
        Feb 16 at 18:21













      • @Jharod The fancyvrb solution should definitely work, and is a much better solution that a ton of copied code you don't understand. If you edit your question to show a non-working fancyvrb example, we could help you with that.

        – Alan Munn
        Feb 16 at 18:22














      3












      3








      3







      You can turn | into inline verbatim like doc.sty does:



      documentclass{article}

      makeatletter
      %Shamelessly copied from doc.sty
      defMakeShortVerb{%>>>
      @ifstar
      {def@shortvrbdef{verb*}@MakeShortVerb}%
      {def@shortvrbdef{verb}@MakeShortVerb}}%<<<
      def@MakeShortVerb#1{%>>>
      expandafterifxcsname ccstring#1endcsnamerelax
      @shortvrbinfo{Made }{#1}@shortvrbdef
      add@special{#1}%
      expandafter
      xdefcsname ccstring#1endcsname{thecatcode`#1}%
      begingroup
      catcode`~active lccode`~`#1%
      lowercase{%
      globalexpandafterlet
      csname acstring#1endcsname~%
      expandaftergdefexpandafter~expandafter{@shortvrbdef~}}%
      endgroup
      globalcatcode`#1active
      else
      @shortvrbinfo@empty{#1 already}{@emptyverb(*)}%
      fi}%<<<
      defDeleteShortVerb#1{%>>>
      expandafterifxcsname ccstring#1endcsnamerelax
      @shortvrbinfo@empty{#1 not}{@emptyverb(*)}%
      else
      @shortvrbinfo{Deleted }{#1 as}{@emptyverb(*)}%
      rem@special{#1}%
      globalcatcode`#1csname ccstring#1endcsname
      global expandafterlet csname ccstring#1endcsname relax
      ifnumcatcode`#1=active
      begingroup
      catcode`~active lccode`~`#1%
      lowercase{%
      globalexpandafterletexpandafter~%
      csname acstring#1endcsname}%
      endgroup fi fi}%<<<
      def@shortvrbinfo#1#2#3{%>>>
      PackageInfo{doc}{%
      #1expandafter@gobblestring#2 a short reference
      for expandafterstring#3}}%<<<
      defadd@special#1{%>>>
      rem@special{#1}%
      expandaftergdefexpandafterdospecialsexpandafter
      {dospecials do #1}%
      expandaftergdefexpandafter@sanitizeexpandafter
      {@sanitize @makeother #1}}%<<<
      defrem@special#1{%>>>
      defdo##1{%
      ifnum`#1=`##1 else noexpanddonoexpand##1fi}%
      xdefdospecials{dospecials}%
      begingroup
      def@makeother##1{%
      ifnum`#1=`##1 else noexpand@makeothernoexpand##1fi}%
      xdef@sanitize{@sanitize}%
      endgroup}%<<<
      AtBeginDocument{MakeShortVerb |}
      AtEndDocument{DeleteShortVerb |}
      makeatother

      begin{document}
      |Test|

      but also |Test$_{}|
      end{document}





      share|improve this answer















      You can turn | into inline verbatim like doc.sty does:



      documentclass{article}

      makeatletter
      %Shamelessly copied from doc.sty
      defMakeShortVerb{%>>>
      @ifstar
      {def@shortvrbdef{verb*}@MakeShortVerb}%
      {def@shortvrbdef{verb}@MakeShortVerb}}%<<<
      def@MakeShortVerb#1{%>>>
      expandafterifxcsname ccstring#1endcsnamerelax
      @shortvrbinfo{Made }{#1}@shortvrbdef
      add@special{#1}%
      expandafter
      xdefcsname ccstring#1endcsname{thecatcode`#1}%
      begingroup
      catcode`~active lccode`~`#1%
      lowercase{%
      globalexpandafterlet
      csname acstring#1endcsname~%
      expandaftergdefexpandafter~expandafter{@shortvrbdef~}}%
      endgroup
      globalcatcode`#1active
      else
      @shortvrbinfo@empty{#1 already}{@emptyverb(*)}%
      fi}%<<<
      defDeleteShortVerb#1{%>>>
      expandafterifxcsname ccstring#1endcsnamerelax
      @shortvrbinfo@empty{#1 not}{@emptyverb(*)}%
      else
      @shortvrbinfo{Deleted }{#1 as}{@emptyverb(*)}%
      rem@special{#1}%
      globalcatcode`#1csname ccstring#1endcsname
      global expandafterlet csname ccstring#1endcsname relax
      ifnumcatcode`#1=active
      begingroup
      catcode`~active lccode`~`#1%
      lowercase{%
      globalexpandafterletexpandafter~%
      csname acstring#1endcsname}%
      endgroup fi fi}%<<<
      def@shortvrbinfo#1#2#3{%>>>
      PackageInfo{doc}{%
      #1expandafter@gobblestring#2 a short reference
      for expandafterstring#3}}%<<<
      defadd@special#1{%>>>
      rem@special{#1}%
      expandaftergdefexpandafterdospecialsexpandafter
      {dospecials do #1}%
      expandaftergdefexpandafter@sanitizeexpandafter
      {@sanitize @makeother #1}}%<<<
      defrem@special#1{%>>>
      defdo##1{%
      ifnum`#1=`##1 else noexpanddonoexpand##1fi}%
      xdefdospecials{dospecials}%
      begingroup
      def@makeother##1{%
      ifnum`#1=`##1 else noexpand@makeothernoexpand##1fi}%
      xdef@sanitize{@sanitize}%
      endgroup}%<<<
      AtBeginDocument{MakeShortVerb |}
      AtEndDocument{DeleteShortVerb |}
      makeatother

      begin{document}
      |Test|

      but also |Test$_{}|
      end{document}






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Feb 16 at 18:24

























      answered Feb 16 at 18:15









      SkillmonSkillmon

      22.7k11943




      22.7k11943








      • 2





        Rather than copying all this code, it's probably easier just to load the fancyvrb package which provides a DefineShortVerb macro to do the same thing.

        – Alan Munn
        Feb 16 at 18:18











      • @AlanMunn yes, that would have been better... Do you want to answer or should I edit mine?

        – Skillmon
        Feb 16 at 18:19











      • The idea is the same; I would just edit your answer to do it that way.

        – Alan Munn
        Feb 16 at 18:20











      • I tried fancyvrb but it didn't work. The copy/paste blob works perfectly and I don't mind it since I have a separate preamble.tex file to hide it in. I do have one further question -- the blob is really hard to understand and I'm wondering how to add a highlight to the contents?

        – Jharod
        Feb 16 at 18:21













      • @Jharod The fancyvrb solution should definitely work, and is a much better solution that a ton of copied code you don't understand. If you edit your question to show a non-working fancyvrb example, we could help you with that.

        – Alan Munn
        Feb 16 at 18:22














      • 2





        Rather than copying all this code, it's probably easier just to load the fancyvrb package which provides a DefineShortVerb macro to do the same thing.

        – Alan Munn
        Feb 16 at 18:18











      • @AlanMunn yes, that would have been better... Do you want to answer or should I edit mine?

        – Skillmon
        Feb 16 at 18:19











      • The idea is the same; I would just edit your answer to do it that way.

        – Alan Munn
        Feb 16 at 18:20











      • I tried fancyvrb but it didn't work. The copy/paste blob works perfectly and I don't mind it since I have a separate preamble.tex file to hide it in. I do have one further question -- the blob is really hard to understand and I'm wondering how to add a highlight to the contents?

        – Jharod
        Feb 16 at 18:21













      • @Jharod The fancyvrb solution should definitely work, and is a much better solution that a ton of copied code you don't understand. If you edit your question to show a non-working fancyvrb example, we could help you with that.

        – Alan Munn
        Feb 16 at 18:22








      2




      2





      Rather than copying all this code, it's probably easier just to load the fancyvrb package which provides a DefineShortVerb macro to do the same thing.

      – Alan Munn
      Feb 16 at 18:18





      Rather than copying all this code, it's probably easier just to load the fancyvrb package which provides a DefineShortVerb macro to do the same thing.

      – Alan Munn
      Feb 16 at 18:18













      @AlanMunn yes, that would have been better... Do you want to answer or should I edit mine?

      – Skillmon
      Feb 16 at 18:19





      @AlanMunn yes, that would have been better... Do you want to answer or should I edit mine?

      – Skillmon
      Feb 16 at 18:19













      The idea is the same; I would just edit your answer to do it that way.

      – Alan Munn
      Feb 16 at 18:20





      The idea is the same; I would just edit your answer to do it that way.

      – Alan Munn
      Feb 16 at 18:20













      I tried fancyvrb but it didn't work. The copy/paste blob works perfectly and I don't mind it since I have a separate preamble.tex file to hide it in. I do have one further question -- the blob is really hard to understand and I'm wondering how to add a highlight to the contents?

      – Jharod
      Feb 16 at 18:21







      I tried fancyvrb but it didn't work. The copy/paste blob works perfectly and I don't mind it since I have a separate preamble.tex file to hide it in. I do have one further question -- the blob is really hard to understand and I'm wondering how to add a highlight to the contents?

      – Jharod
      Feb 16 at 18:21















      @Jharod The fancyvrb solution should definitely work, and is a much better solution that a ton of copied code you don't understand. If you edit your question to show a non-working fancyvrb example, we could help you with that.

      – Alan Munn
      Feb 16 at 18:22





      @Jharod The fancyvrb solution should definitely work, and is a much better solution that a ton of copied code you don't understand. If you edit your question to show a non-working fancyvrb example, we could help you with that.

      – Alan Munn
      Feb 16 at 18:22











      3














      It looks like you want an inline verbatim environment. The fancyvrb package provides a simple way to do that. Note that, just like the Skillmon's solution, you cannot define the backtick to be the verbatim delimiter with this approach. Alternatively, if you just don't like having to type texttt all the time you could make a shorter replacement macro for it. Here I've used vrb. Notice how the fancyvrb version allows the use of reserved TeX characters without being escaped; the texttt solution does not.



      documentclass{article}
      usepackage{fancyvrb}
      DefineShortVerb{|}
      newcommand{vrb}{texttt}
      begin{document}

      Using the |fancyvrb| |foo|

      Using a macro |vrb{foo}| vrb{foo}

      end{document}


      output of code






      share|improve this answer






























        3














        It looks like you want an inline verbatim environment. The fancyvrb package provides a simple way to do that. Note that, just like the Skillmon's solution, you cannot define the backtick to be the verbatim delimiter with this approach. Alternatively, if you just don't like having to type texttt all the time you could make a shorter replacement macro for it. Here I've used vrb. Notice how the fancyvrb version allows the use of reserved TeX characters without being escaped; the texttt solution does not.



        documentclass{article}
        usepackage{fancyvrb}
        DefineShortVerb{|}
        newcommand{vrb}{texttt}
        begin{document}

        Using the |fancyvrb| |foo|

        Using a macro |vrb{foo}| vrb{foo}

        end{document}


        output of code






        share|improve this answer




























          3












          3








          3







          It looks like you want an inline verbatim environment. The fancyvrb package provides a simple way to do that. Note that, just like the Skillmon's solution, you cannot define the backtick to be the verbatim delimiter with this approach. Alternatively, if you just don't like having to type texttt all the time you could make a shorter replacement macro for it. Here I've used vrb. Notice how the fancyvrb version allows the use of reserved TeX characters without being escaped; the texttt solution does not.



          documentclass{article}
          usepackage{fancyvrb}
          DefineShortVerb{|}
          newcommand{vrb}{texttt}
          begin{document}

          Using the |fancyvrb| |foo|

          Using a macro |vrb{foo}| vrb{foo}

          end{document}


          output of code






          share|improve this answer















          It looks like you want an inline verbatim environment. The fancyvrb package provides a simple way to do that. Note that, just like the Skillmon's solution, you cannot define the backtick to be the verbatim delimiter with this approach. Alternatively, if you just don't like having to type texttt all the time you could make a shorter replacement macro for it. Here I've used vrb. Notice how the fancyvrb version allows the use of reserved TeX characters without being escaped; the texttt solution does not.



          documentclass{article}
          usepackage{fancyvrb}
          DefineShortVerb{|}
          newcommand{vrb}{texttt}
          begin{document}

          Using the |fancyvrb| |foo|

          Using a macro |vrb{foo}| vrb{foo}

          end{document}


          output of code







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Feb 16 at 18:34

























          answered Feb 16 at 18:27









          Alan MunnAlan Munn

          161k28429705




          161k28429705























              2














              Not really complicated and, differently from other proposed answers, the object can go in the argument to another command.



              Thus something like mbox{`const WIDTH = 5`} will work.



              documentclass{article}

              makeatletter
              % define the active backquote
              begingrouplccode`~=``lowercase{endgroup
              def~#1~{texttt{#1}}%
              }
              % delay activating at begin document
              AtBeginDocument{catcode``=active}
              makeatother

              begin{document}

              This is texttt{const WIDTH = 5}

              This is `const WIDTH = 5`

              end{document}


              Beware it is quite fragile and finding a missing backquote could be difficult. It's simpler if you define some shortcut with your editor.



              enter image description here



              Even more fragile with double back quotes for denoting verbatim mode (however, the double back quotes cannot be used in the argument to another command, just like verb).



              documentclass{article}

              makeatletter
              % define the active backquote
              begingrouplccode`~=``lowercase{endgroup
              defjharodbackquote{@ifnextchar~jharodverbjharodtt}
              defjharodtt#1~{texttt{#1}}
              let~jharodbackquote
              defjharodverb{bgroupcatcode``=2 verb}
              }
              % delay activating at begin document
              AtBeginDocument{catcode``=active}
              makeatother

              begin{document}

              This is mbox{`const WIDTH = 5`}

              This is `const WIDTH = 5`

              This is ``verb{atim}``

              This is `const WIDTH = 5`

              end{document}


              enter image description here






              share|improve this answer






























                2














                Not really complicated and, differently from other proposed answers, the object can go in the argument to another command.



                Thus something like mbox{`const WIDTH = 5`} will work.



                documentclass{article}

                makeatletter
                % define the active backquote
                begingrouplccode`~=``lowercase{endgroup
                def~#1~{texttt{#1}}%
                }
                % delay activating at begin document
                AtBeginDocument{catcode``=active}
                makeatother

                begin{document}

                This is texttt{const WIDTH = 5}

                This is `const WIDTH = 5`

                end{document}


                Beware it is quite fragile and finding a missing backquote could be difficult. It's simpler if you define some shortcut with your editor.



                enter image description here



                Even more fragile with double back quotes for denoting verbatim mode (however, the double back quotes cannot be used in the argument to another command, just like verb).



                documentclass{article}

                makeatletter
                % define the active backquote
                begingrouplccode`~=``lowercase{endgroup
                defjharodbackquote{@ifnextchar~jharodverbjharodtt}
                defjharodtt#1~{texttt{#1}}
                let~jharodbackquote
                defjharodverb{bgroupcatcode``=2 verb}
                }
                % delay activating at begin document
                AtBeginDocument{catcode``=active}
                makeatother

                begin{document}

                This is mbox{`const WIDTH = 5`}

                This is `const WIDTH = 5`

                This is ``verb{atim}``

                This is `const WIDTH = 5`

                end{document}


                enter image description here






                share|improve this answer




























                  2












                  2








                  2







                  Not really complicated and, differently from other proposed answers, the object can go in the argument to another command.



                  Thus something like mbox{`const WIDTH = 5`} will work.



                  documentclass{article}

                  makeatletter
                  % define the active backquote
                  begingrouplccode`~=``lowercase{endgroup
                  def~#1~{texttt{#1}}%
                  }
                  % delay activating at begin document
                  AtBeginDocument{catcode``=active}
                  makeatother

                  begin{document}

                  This is texttt{const WIDTH = 5}

                  This is `const WIDTH = 5`

                  end{document}


                  Beware it is quite fragile and finding a missing backquote could be difficult. It's simpler if you define some shortcut with your editor.



                  enter image description here



                  Even more fragile with double back quotes for denoting verbatim mode (however, the double back quotes cannot be used in the argument to another command, just like verb).



                  documentclass{article}

                  makeatletter
                  % define the active backquote
                  begingrouplccode`~=``lowercase{endgroup
                  defjharodbackquote{@ifnextchar~jharodverbjharodtt}
                  defjharodtt#1~{texttt{#1}}
                  let~jharodbackquote
                  defjharodverb{bgroupcatcode``=2 verb}
                  }
                  % delay activating at begin document
                  AtBeginDocument{catcode``=active}
                  makeatother

                  begin{document}

                  This is mbox{`const WIDTH = 5`}

                  This is `const WIDTH = 5`

                  This is ``verb{atim}``

                  This is `const WIDTH = 5`

                  end{document}


                  enter image description here






                  share|improve this answer















                  Not really complicated and, differently from other proposed answers, the object can go in the argument to another command.



                  Thus something like mbox{`const WIDTH = 5`} will work.



                  documentclass{article}

                  makeatletter
                  % define the active backquote
                  begingrouplccode`~=``lowercase{endgroup
                  def~#1~{texttt{#1}}%
                  }
                  % delay activating at begin document
                  AtBeginDocument{catcode``=active}
                  makeatother

                  begin{document}

                  This is texttt{const WIDTH = 5}

                  This is `const WIDTH = 5`

                  end{document}


                  Beware it is quite fragile and finding a missing backquote could be difficult. It's simpler if you define some shortcut with your editor.



                  enter image description here



                  Even more fragile with double back quotes for denoting verbatim mode (however, the double back quotes cannot be used in the argument to another command, just like verb).



                  documentclass{article}

                  makeatletter
                  % define the active backquote
                  begingrouplccode`~=``lowercase{endgroup
                  defjharodbackquote{@ifnextchar~jharodverbjharodtt}
                  defjharodtt#1~{texttt{#1}}
                  let~jharodbackquote
                  defjharodverb{bgroupcatcode``=2 verb}
                  }
                  % delay activating at begin document
                  AtBeginDocument{catcode``=active}
                  makeatother

                  begin{document}

                  This is mbox{`const WIDTH = 5`}

                  This is `const WIDTH = 5`

                  This is ``verb{atim}``

                  This is `const WIDTH = 5`

                  end{document}


                  enter image description here







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Feb 16 at 18:39

























                  answered Feb 16 at 18:23









                  egregegreg

                  722k8719143213




                  722k8719143213






























                      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%2f475230%2finline-environment-shortcut-like-blah%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

                      Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

                      ComboBox Display Member on multiple fields

                      Is it possible to collect Nectar points via Trainline?