Typing CO_2 easily












15















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.





















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

    – KJO
    Mar 20 at 2:48








  • 6





    For anyone new to latex reading this question: There are two separate issues here. One is that mathrm can only be used in math mode. The second one is that you can't (usually) have digits in macro names.

    – sgf
    Mar 20 at 15:35











  • Oh I did not realize you couldn't have digits in macro names! Cool, thanks!

    – Hayley
    Mar 21 at 0:36
















15















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.





















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

    – KJO
    Mar 20 at 2:48








  • 6





    For anyone new to latex reading this question: There are two separate issues here. One is that mathrm can only be used in math mode. The second one is that you can't (usually) have digits in macro names.

    – sgf
    Mar 20 at 15:35











  • Oh I did not realize you couldn't have digits in macro names! Cool, thanks!

    – Hayley
    Mar 21 at 0:36














15












15








15








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 Mar 20 at 11:03









Phelype Oleinik

24.6k54688




24.6k54688






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 Mar 20 at 2:02









HayleyHayley

785




785




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.













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

    – KJO
    Mar 20 at 2:48








  • 6





    For anyone new to latex reading this question: There are two separate issues here. One is that mathrm can only be used in math mode. The second one is that you can't (usually) have digits in macro names.

    – sgf
    Mar 20 at 15:35











  • Oh I did not realize you couldn't have digits in macro names! Cool, thanks!

    – Hayley
    Mar 21 at 0:36



















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

    – KJO
    Mar 20 at 2:48








  • 6





    For anyone new to latex reading this question: There are two separate issues here. One is that mathrm can only be used in math mode. The second one is that you can't (usually) have digits in macro names.

    – sgf
    Mar 20 at 15:35











  • Oh I did not realize you couldn't have digits in macro names! Cool, thanks!

    – Hayley
    Mar 21 at 0:36

















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

– KJO
Mar 20 at 2:48







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

– KJO
Mar 20 at 2:48






6




6





For anyone new to latex reading this question: There are two separate issues here. One is that mathrm can only be used in math mode. The second one is that you can't (usually) have digits in macro names.

– sgf
Mar 20 at 15:35





For anyone new to latex reading this question: There are two separate issues here. One is that mathrm can only be used in math mode. The second one is that you can't (usually) have digits in macro names.

– sgf
Mar 20 at 15:35













Oh I did not realize you couldn't have digits in macro names! Cool, thanks!

– Hayley
Mar 21 at 0:36





Oh I did not realize you couldn't have digits in macro names! Cool, thanks!

– Hayley
Mar 21 at 0:36










4 Answers
4






active

oldest

votes


















17














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
























  • Or use coo{} in text mode, which avoids worries about the space getting eaten by something.

    – David Richerby
    Mar 20 at 20:35











  • Perfect, thank you!

    – Hayley
    Mar 21 at 0:36






  • 1





    Especially when using macros, I think that using xspace is really convenient. You put an xspace at the end of your macro and it will decide if a space is necessary or not.

    – Ian
    Mar 21 at 7:23



















52














You want easy?



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





share|improve this answer



















  • 18





    For completeness, you might mention also mhchem

    – egreg
    Mar 20 at 9:04



















21














I would use the mhchem package. It makes a lot of chemistry things easier, including reactions as well as formulas.



Put the line



usepackage{mhchem}


in the header section of your document, and then CO2 is just ce{CO2}. You can use that in math mode or text mode, it works either way. Here are some examples of other formulae from the package documentation, to give an idea of what you can do. (Note from the very first example how easy it is to write a simple reaction.)



(Note also that, as mentioned in John Kormylo's answer, there is also a package chemformula. It seems to be very similar, and allows you to do the same things in very similar ways. It is a more recent package, but I have no experience with it.)



examples



more examples



more examples



more examples






share|improve this answer

































    0














    Using isotope package with the macro cotwo you can write easily and quickly CO_2:



    enter image description here



    documentclass{article}
    usepackage{isotope}
    newcommand{cotwo}{$isotope{CO}_2$}

    begin{document}

    cotwo

    end{document}





    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

























      4 Answers
      4






      active

      oldest

      votes








      4 Answers
      4






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      17














      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
























      • Or use coo{} in text mode, which avoids worries about the space getting eaten by something.

        – David Richerby
        Mar 20 at 20:35











      • Perfect, thank you!

        – Hayley
        Mar 21 at 0:36






      • 1





        Especially when using macros, I think that using xspace is really convenient. You put an xspace at the end of your macro and it will decide if a space is necessary or not.

        – Ian
        Mar 21 at 7:23
















      17














      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
























      • Or use coo{} in text mode, which avoids worries about the space getting eaten by something.

        – David Richerby
        Mar 20 at 20:35











      • Perfect, thank you!

        – Hayley
        Mar 21 at 0:36






      • 1





        Especially when using macros, I think that using xspace is really convenient. You put an xspace at the end of your macro and it will decide if a space is necessary or not.

        – Ian
        Mar 21 at 7:23














      17












      17








      17







      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 Mar 20 at 13:13









      Sandy GSandy G

      4,2051632




      4,2051632













      • Or use coo{} in text mode, which avoids worries about the space getting eaten by something.

        – David Richerby
        Mar 20 at 20:35











      • Perfect, thank you!

        – Hayley
        Mar 21 at 0:36






      • 1





        Especially when using macros, I think that using xspace is really convenient. You put an xspace at the end of your macro and it will decide if a space is necessary or not.

        – Ian
        Mar 21 at 7:23



















      • Or use coo{} in text mode, which avoids worries about the space getting eaten by something.

        – David Richerby
        Mar 20 at 20:35











      • Perfect, thank you!

        – Hayley
        Mar 21 at 0:36






      • 1





        Especially when using macros, I think that using xspace is really convenient. You put an xspace at the end of your macro and it will decide if a space is necessary or not.

        – Ian
        Mar 21 at 7:23

















      Or use coo{} in text mode, which avoids worries about the space getting eaten by something.

      – David Richerby
      Mar 20 at 20:35





      Or use coo{} in text mode, which avoids worries about the space getting eaten by something.

      – David Richerby
      Mar 20 at 20:35













      Perfect, thank you!

      – Hayley
      Mar 21 at 0:36





      Perfect, thank you!

      – Hayley
      Mar 21 at 0:36




      1




      1





      Especially when using macros, I think that using xspace is really convenient. You put an xspace at the end of your macro and it will decide if a space is necessary or not.

      – Ian
      Mar 21 at 7:23





      Especially when using macros, I think that using xspace is really convenient. You put an xspace at the end of your macro and it will decide if a space is necessary or not.

      – Ian
      Mar 21 at 7:23











      52














      You want easy?



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





      share|improve this answer



















      • 18





        For completeness, you might mention also mhchem

        – egreg
        Mar 20 at 9:04
















      52














      You want easy?



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





      share|improve this answer



















      • 18





        For completeness, you might mention also mhchem

        – egreg
        Mar 20 at 9:04














      52












      52








      52







      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 Mar 20 at 3:23









      John KormyloJohn Kormylo

      45.9k22672




      45.9k22672








      • 18





        For completeness, you might mention also mhchem

        – egreg
        Mar 20 at 9:04














      • 18





        For completeness, you might mention also mhchem

        – egreg
        Mar 20 at 9:04








      18




      18





      For completeness, you might mention also mhchem

      – egreg
      Mar 20 at 9:04





      For completeness, you might mention also mhchem

      – egreg
      Mar 20 at 9:04











      21














      I would use the mhchem package. It makes a lot of chemistry things easier, including reactions as well as formulas.



      Put the line



      usepackage{mhchem}


      in the header section of your document, and then CO2 is just ce{CO2}. You can use that in math mode or text mode, it works either way. Here are some examples of other formulae from the package documentation, to give an idea of what you can do. (Note from the very first example how easy it is to write a simple reaction.)



      (Note also that, as mentioned in John Kormylo's answer, there is also a package chemformula. It seems to be very similar, and allows you to do the same things in very similar ways. It is a more recent package, but I have no experience with it.)



      examples



      more examples



      more examples



      more examples






      share|improve this answer






























        21














        I would use the mhchem package. It makes a lot of chemistry things easier, including reactions as well as formulas.



        Put the line



        usepackage{mhchem}


        in the header section of your document, and then CO2 is just ce{CO2}. You can use that in math mode or text mode, it works either way. Here are some examples of other formulae from the package documentation, to give an idea of what you can do. (Note from the very first example how easy it is to write a simple reaction.)



        (Note also that, as mentioned in John Kormylo's answer, there is also a package chemformula. It seems to be very similar, and allows you to do the same things in very similar ways. It is a more recent package, but I have no experience with it.)



        examples



        more examples



        more examples



        more examples






        share|improve this answer




























          21












          21








          21







          I would use the mhchem package. It makes a lot of chemistry things easier, including reactions as well as formulas.



          Put the line



          usepackage{mhchem}


          in the header section of your document, and then CO2 is just ce{CO2}. You can use that in math mode or text mode, it works either way. Here are some examples of other formulae from the package documentation, to give an idea of what you can do. (Note from the very first example how easy it is to write a simple reaction.)



          (Note also that, as mentioned in John Kormylo's answer, there is also a package chemformula. It seems to be very similar, and allows you to do the same things in very similar ways. It is a more recent package, but I have no experience with it.)



          examples



          more examples



          more examples



          more examples






          share|improve this answer















          I would use the mhchem package. It makes a lot of chemistry things easier, including reactions as well as formulas.



          Put the line



          usepackage{mhchem}


          in the header section of your document, and then CO2 is just ce{CO2}. You can use that in math mode or text mode, it works either way. Here are some examples of other formulae from the package documentation, to give an idea of what you can do. (Note from the very first example how easy it is to write a simple reaction.)



          (Note also that, as mentioned in John Kormylo's answer, there is also a package chemformula. It seems to be very similar, and allows you to do the same things in very similar ways. It is a more recent package, but I have no experience with it.)



          examples



          more examples



          more examples



          more examples







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 21 at 9:25

























          answered Mar 21 at 9:11









          NathanielNathaniel

          1,00721126




          1,00721126























              0














              Using isotope package with the macro cotwo you can write easily and quickly CO_2:



              enter image description here



              documentclass{article}
              usepackage{isotope}
              newcommand{cotwo}{$isotope{CO}_2$}

              begin{document}

              cotwo

              end{document}





              share|improve this answer




























                0














                Using isotope package with the macro cotwo you can write easily and quickly CO_2:



                enter image description here



                documentclass{article}
                usepackage{isotope}
                newcommand{cotwo}{$isotope{CO}_2$}

                begin{document}

                cotwo

                end{document}





                share|improve this answer


























                  0












                  0








                  0







                  Using isotope package with the macro cotwo you can write easily and quickly CO_2:



                  enter image description here



                  documentclass{article}
                  usepackage{isotope}
                  newcommand{cotwo}{$isotope{CO}_2$}

                  begin{document}

                  cotwo

                  end{document}





                  share|improve this answer













                  Using isotope package with the macro cotwo you can write easily and quickly CO_2:



                  enter image description here



                  documentclass{article}
                  usepackage{isotope}
                  newcommand{cotwo}{$isotope{CO}_2$}

                  begin{document}

                  cotwo

                  end{document}






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 24 mins ago









                  SebastianoSebastiano

                  11.1k42164




                  11.1k42164






















                      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

                      Paul Cézanne

                      UIScrollView CustomStickyHeader Resize height generates problems when scroll is too fast

                      Angular material date-picker (MatDatepicker) auto completes the date on focus out