Typing CO_2 easily












3















I'm writing my dissertation and that involves typing a lot of $mathrm{CO_2}$. I'd like to make a macro for it that's a lot easier to type, but if I put newcommand{co2}{mathrm{CO_2}}, for example, it gives me the error that mathrm can only be used in math mode. But using newcommand{co2}{$mathrm{CO_2}$} doesn't work either.



Is there a way for me to make a macro that makes typing CO_2 easier, even if it doesn't use mathrm?










share|improve this question









New contributor




Hayley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • Welcome to TeX.SE! Can you show a short compilable tex code resulting in your issue?

    – Kurt
    11 hours ago











  • Have you tried newcommand{cotwo}{mathrm{CO_2}} see tex.stackexchange.com/questions/44545/… also tex.stackexchange.com/questions/393855/…

    – KJO
    10 hours ago













  • If this will only be used in text mode, newcommand{coo}{COtextsubscript{2}} will work. If you are using the macro in both math and text, you could use newcommand{coo}{ensuremath{mathrm{CO_2}}}. Note, that you need a trailing slash and space in the text call: sometext coo sometext

    – Sandy G
    30 mins ago
















3















I'm writing my dissertation and that involves typing a lot of $mathrm{CO_2}$. I'd like to make a macro for it that's a lot easier to type, but if I put newcommand{co2}{mathrm{CO_2}}, for example, it gives me the error that mathrm can only be used in math mode. But using newcommand{co2}{$mathrm{CO_2}$} doesn't work either.



Is there a way for me to make a macro that makes typing CO_2 easier, even if it doesn't use mathrm?










share|improve this question









New contributor




Hayley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • Welcome to TeX.SE! Can you show a short compilable tex code resulting in your issue?

    – Kurt
    11 hours ago











  • Have you tried newcommand{cotwo}{mathrm{CO_2}} see tex.stackexchange.com/questions/44545/… also tex.stackexchange.com/questions/393855/…

    – KJO
    10 hours ago













  • If this will only be used in text mode, newcommand{coo}{COtextsubscript{2}} will work. If you are using the macro in both math and text, you could use newcommand{coo}{ensuremath{mathrm{CO_2}}}. Note, that you need a trailing slash and space in the text call: sometext coo sometext

    – Sandy G
    30 mins ago














3












3








3








I'm writing my dissertation and that involves typing a lot of $mathrm{CO_2}$. I'd like to make a macro for it that's a lot easier to type, but if I put newcommand{co2}{mathrm{CO_2}}, for example, it gives me the error that mathrm can only be used in math mode. But using newcommand{co2}{$mathrm{CO_2}$} doesn't work either.



Is there a way for me to make a macro that makes typing CO_2 easier, even if it doesn't use mathrm?










share|improve this question









New contributor




Hayley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












I'm writing my dissertation and that involves typing a lot of $mathrm{CO_2}$. I'd like to make a macro for it that's a lot easier to type, but if I put newcommand{co2}{mathrm{CO_2}}, for example, it gives me the error that mathrm can only be used in math mode. But using newcommand{co2}{$mathrm{CO_2}$} doesn't work either.



Is there a way for me to make a macro that makes typing CO_2 easier, even if it doesn't use mathrm?







chemistry






share|improve this question









New contributor




Hayley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Hayley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 2 hours ago









Phelype Oleinik

24.4k54688




24.4k54688






New contributor




Hayley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 11 hours ago









HayleyHayley

161




161




New contributor




Hayley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Hayley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Hayley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.













  • Welcome to TeX.SE! Can you show a short compilable tex code resulting in your issue?

    – Kurt
    11 hours ago











  • Have you tried newcommand{cotwo}{mathrm{CO_2}} see tex.stackexchange.com/questions/44545/… also tex.stackexchange.com/questions/393855/…

    – KJO
    10 hours ago













  • If this will only be used in text mode, newcommand{coo}{COtextsubscript{2}} will work. If you are using the macro in both math and text, you could use newcommand{coo}{ensuremath{mathrm{CO_2}}}. Note, that you need a trailing slash and space in the text call: sometext coo sometext

    – Sandy G
    30 mins ago



















  • Welcome to TeX.SE! Can you show a short compilable tex code resulting in your issue?

    – Kurt
    11 hours ago











  • Have you tried newcommand{cotwo}{mathrm{CO_2}} see tex.stackexchange.com/questions/44545/… also tex.stackexchange.com/questions/393855/…

    – KJO
    10 hours ago













  • If this will only be used in text mode, newcommand{coo}{COtextsubscript{2}} will work. If you are using the macro in both math and text, you could use newcommand{coo}{ensuremath{mathrm{CO_2}}}. Note, that you need a trailing slash and space in the text call: sometext coo sometext

    – Sandy G
    30 mins ago

















Welcome to TeX.SE! Can you show a short compilable tex code resulting in your issue?

– Kurt
11 hours ago





Welcome to TeX.SE! Can you show a short compilable tex code resulting in your issue?

– Kurt
11 hours ago













Have you tried newcommand{cotwo}{mathrm{CO_2}} see tex.stackexchange.com/questions/44545/… also tex.stackexchange.com/questions/393855/…

– KJO
10 hours ago







Have you tried newcommand{cotwo}{mathrm{CO_2}} see tex.stackexchange.com/questions/44545/… also tex.stackexchange.com/questions/393855/…

– KJO
10 hours ago















If this will only be used in text mode, newcommand{coo}{COtextsubscript{2}} will work. If you are using the macro in both math and text, you could use newcommand{coo}{ensuremath{mathrm{CO_2}}}. Note, that you need a trailing slash and space in the text call: sometext coo sometext

– Sandy G
30 mins ago





If this will only be used in text mode, newcommand{coo}{COtextsubscript{2}} will work. If you are using the macro in both math and text, you could use newcommand{coo}{ensuremath{mathrm{CO_2}}}. Note, that you need a trailing slash and space in the text call: sometext coo sometext

– Sandy G
30 mins ago










3 Answers
3






active

oldest

votes


















12














You want easy?



documentclass{article}  
usepackage{chemformula}
begin{document}
ch{CO2}
end{document}





share|improve this answer
























  • Indeed, very easy. +1

    – marmot
    9 hours ago






  • 4





    For completeness, you might mention also mhchem

    – egreg
    4 hours ago



















4














documentclass[a4paper]{article}

makeatletter
newcommandUD@exchange[2]{#2#1}%
newcommandname{}%
longdefname#1#{romannumeral0@name{#1}}%
newcommand@name[2]{%
expandafterUD@exchangeexpandafter{csname#2endcsname}{ #1}%
}%
makeatother

% Variant 1: Via csname..endcsname define a macro whose name is CO_2

namenewcommand{CO_2}{$mathrm{CO_2}$}%

% Variant 2: Define a macro CO which as parameter text has the delimiter _2

newcommandCO{}%
defCO_2{$mathrm{CO_2}$}%

begin{document}

name{CO_2}

CO_2

end{document}


enter image description here



(I elaborated on the name-macro in my answer to the question "How to implement expandbefore, similarly to expandafter?".)






share|improve this answer

































    2














    I'm not sure if this is a question about how to use co2 as a macro name or just a question about how to subscript in text mode. If you use coo, the macro



    newcommand{coo}{ensuremath{mathrm{CO_2}}}


    works fine in both text and math mode. If you're only planning to use the macro in text mode, COtextsubscript{2} works.



    enter image description here



    documentclass{article}

    newcommand{coo}{ensuremath{mathrm{CO_2}}}
    newcommand{cooo}{COtextsubscript{2}}

    begin{document}

    With ensuremath: Text coo and math $coo$ both look fine.

    With textsubscript: Text cooo is fine, but math $cooo$ isn't.

    end{document}


    Don't forget the trainling and space after the call in text mode.






    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
      });


      }
      });






      Hayley is a new contributor. Be nice, and check out our Code of Conduct.










      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f480391%2ftyping-co-2-easily%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









      12














      You want easy?



      documentclass{article}  
      usepackage{chemformula}
      begin{document}
      ch{CO2}
      end{document}





      share|improve this answer
























      • Indeed, very easy. +1

        – marmot
        9 hours ago






      • 4





        For completeness, you might mention also mhchem

        – egreg
        4 hours ago
















      12














      You want easy?



      documentclass{article}  
      usepackage{chemformula}
      begin{document}
      ch{CO2}
      end{document}





      share|improve this answer
























      • Indeed, very easy. +1

        – marmot
        9 hours ago






      • 4





        For completeness, you might mention also mhchem

        – egreg
        4 hours ago














      12












      12








      12







      You want easy?



      documentclass{article}  
      usepackage{chemformula}
      begin{document}
      ch{CO2}
      end{document}





      share|improve this answer













      You want easy?



      documentclass{article}  
      usepackage{chemformula}
      begin{document}
      ch{CO2}
      end{document}






      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered 10 hours ago









      John KormyloJohn Kormylo

      45.5k12571




      45.5k12571













      • Indeed, very easy. +1

        – marmot
        9 hours ago






      • 4





        For completeness, you might mention also mhchem

        – egreg
        4 hours ago



















      • Indeed, very easy. +1

        – marmot
        9 hours ago






      • 4





        For completeness, you might mention also mhchem

        – egreg
        4 hours ago

















      Indeed, very easy. +1

      – marmot
      9 hours ago





      Indeed, very easy. +1

      – marmot
      9 hours ago




      4




      4





      For completeness, you might mention also mhchem

      – egreg
      4 hours ago





      For completeness, you might mention also mhchem

      – egreg
      4 hours ago











      4














      documentclass[a4paper]{article}

      makeatletter
      newcommandUD@exchange[2]{#2#1}%
      newcommandname{}%
      longdefname#1#{romannumeral0@name{#1}}%
      newcommand@name[2]{%
      expandafterUD@exchangeexpandafter{csname#2endcsname}{ #1}%
      }%
      makeatother

      % Variant 1: Via csname..endcsname define a macro whose name is CO_2

      namenewcommand{CO_2}{$mathrm{CO_2}$}%

      % Variant 2: Define a macro CO which as parameter text has the delimiter _2

      newcommandCO{}%
      defCO_2{$mathrm{CO_2}$}%

      begin{document}

      name{CO_2}

      CO_2

      end{document}


      enter image description here



      (I elaborated on the name-macro in my answer to the question "How to implement expandbefore, similarly to expandafter?".)






      share|improve this answer






























        4














        documentclass[a4paper]{article}

        makeatletter
        newcommandUD@exchange[2]{#2#1}%
        newcommandname{}%
        longdefname#1#{romannumeral0@name{#1}}%
        newcommand@name[2]{%
        expandafterUD@exchangeexpandafter{csname#2endcsname}{ #1}%
        }%
        makeatother

        % Variant 1: Via csname..endcsname define a macro whose name is CO_2

        namenewcommand{CO_2}{$mathrm{CO_2}$}%

        % Variant 2: Define a macro CO which as parameter text has the delimiter _2

        newcommandCO{}%
        defCO_2{$mathrm{CO_2}$}%

        begin{document}

        name{CO_2}

        CO_2

        end{document}


        enter image description here



        (I elaborated on the name-macro in my answer to the question "How to implement expandbefore, similarly to expandafter?".)






        share|improve this answer




























          4












          4








          4







          documentclass[a4paper]{article}

          makeatletter
          newcommandUD@exchange[2]{#2#1}%
          newcommandname{}%
          longdefname#1#{romannumeral0@name{#1}}%
          newcommand@name[2]{%
          expandafterUD@exchangeexpandafter{csname#2endcsname}{ #1}%
          }%
          makeatother

          % Variant 1: Via csname..endcsname define a macro whose name is CO_2

          namenewcommand{CO_2}{$mathrm{CO_2}$}%

          % Variant 2: Define a macro CO which as parameter text has the delimiter _2

          newcommandCO{}%
          defCO_2{$mathrm{CO_2}$}%

          begin{document}

          name{CO_2}

          CO_2

          end{document}


          enter image description here



          (I elaborated on the name-macro in my answer to the question "How to implement expandbefore, similarly to expandafter?".)






          share|improve this answer















          documentclass[a4paper]{article}

          makeatletter
          newcommandUD@exchange[2]{#2#1}%
          newcommandname{}%
          longdefname#1#{romannumeral0@name{#1}}%
          newcommand@name[2]{%
          expandafterUD@exchangeexpandafter{csname#2endcsname}{ #1}%
          }%
          makeatother

          % Variant 1: Via csname..endcsname define a macro whose name is CO_2

          namenewcommand{CO_2}{$mathrm{CO_2}$}%

          % Variant 2: Define a macro CO which as parameter text has the delimiter _2

          newcommandCO{}%
          defCO_2{$mathrm{CO_2}$}%

          begin{document}

          name{CO_2}

          CO_2

          end{document}


          enter image description here



          (I elaborated on the name-macro in my answer to the question "How to implement expandbefore, similarly to expandafter?".)







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 4 hours ago

























          answered 10 hours ago









          Ulrich DiezUlrich Diez

          5,500619




          5,500619























              2














              I'm not sure if this is a question about how to use co2 as a macro name or just a question about how to subscript in text mode. If you use coo, the macro



              newcommand{coo}{ensuremath{mathrm{CO_2}}}


              works fine in both text and math mode. If you're only planning to use the macro in text mode, COtextsubscript{2} works.



              enter image description here



              documentclass{article}

              newcommand{coo}{ensuremath{mathrm{CO_2}}}
              newcommand{cooo}{COtextsubscript{2}}

              begin{document}

              With ensuremath: Text coo and math $coo$ both look fine.

              With textsubscript: Text cooo is fine, but math $cooo$ isn't.

              end{document}


              Don't forget the trainling and space after the call in text mode.






              share|improve this answer




























                2














                I'm not sure if this is a question about how to use co2 as a macro name or just a question about how to subscript in text mode. If you use coo, the macro



                newcommand{coo}{ensuremath{mathrm{CO_2}}}


                works fine in both text and math mode. If you're only planning to use the macro in text mode, COtextsubscript{2} works.



                enter image description here



                documentclass{article}

                newcommand{coo}{ensuremath{mathrm{CO_2}}}
                newcommand{cooo}{COtextsubscript{2}}

                begin{document}

                With ensuremath: Text coo and math $coo$ both look fine.

                With textsubscript: Text cooo is fine, but math $cooo$ isn't.

                end{document}


                Don't forget the trainling and space after the call in text mode.






                share|improve this answer


























                  2












                  2








                  2







                  I'm not sure if this is a question about how to use co2 as a macro name or just a question about how to subscript in text mode. If you use coo, the macro



                  newcommand{coo}{ensuremath{mathrm{CO_2}}}


                  works fine in both text and math mode. If you're only planning to use the macro in text mode, COtextsubscript{2} works.



                  enter image description here



                  documentclass{article}

                  newcommand{coo}{ensuremath{mathrm{CO_2}}}
                  newcommand{cooo}{COtextsubscript{2}}

                  begin{document}

                  With ensuremath: Text coo and math $coo$ both look fine.

                  With textsubscript: Text cooo is fine, but math $cooo$ isn't.

                  end{document}


                  Don't forget the trainling and space after the call in text mode.






                  share|improve this answer













                  I'm not sure if this is a question about how to use co2 as a macro name or just a question about how to subscript in text mode. If you use coo, the macro



                  newcommand{coo}{ensuremath{mathrm{CO_2}}}


                  works fine in both text and math mode. If you're only planning to use the macro in text mode, COtextsubscript{2} works.



                  enter image description here



                  documentclass{article}

                  newcommand{coo}{ensuremath{mathrm{CO_2}}}
                  newcommand{cooo}{COtextsubscript{2}}

                  begin{document}

                  With ensuremath: Text coo and math $coo$ both look fine.

                  With textsubscript: Text cooo is fine, but math $cooo$ isn't.

                  end{document}


                  Don't forget the trainling and space after the call in text mode.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 17 mins ago









                  Sandy GSandy G

                  3,4621425




                  3,4621425






















                      Hayley is a new contributor. Be nice, and check out our Code of Conduct.










                      draft saved

                      draft discarded


















                      Hayley is a new contributor. Be nice, and check out our Code of Conduct.













                      Hayley is a new contributor. Be nice, and check out our Code of Conduct.












                      Hayley is a new contributor. Be nice, and check out our Code of Conduct.
















                      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%2f480391%2ftyping-co-2-easily%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 to make a Squid Proxy server?

                      第一次世界大戦

                      Touch on Surface Book