Typing CO_2 easily












0















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
    1 hour ago











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

    – KJO
    1 hour ago


















0















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
    1 hour ago











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

    – KJO
    1 hour ago
















0












0








0








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?







macros






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









Kurt

39.7k850164




39.7k850164






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 2 hours ago









HayleyHayley

1




1




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
    1 hour ago











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

    – KJO
    1 hour ago





















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

    – Kurt
    1 hour ago











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

    – KJO
    1 hour ago



















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

– Kurt
1 hour ago





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

– Kurt
1 hour ago













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

– KJO
1 hour ago







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

– KJO
1 hour ago












2 Answers
2






active

oldest

votes


















2














You want easy?



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





share|improve this answer
























  • Indeed, very easy. +1

    – marmot
    17 mins ago



















1














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























    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

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    You want easy?



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





    share|improve this answer
























    • Indeed, very easy. +1

      – marmot
      17 mins ago
















    2














    You want easy?



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





    share|improve this answer
























    • Indeed, very easy. +1

      – marmot
      17 mins ago














    2












    2








    2







    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 49 mins ago









    John KormyloJohn Kormylo

    45.4k12570




    45.4k12570













    • Indeed, very easy. +1

      – marmot
      17 mins ago



















    • Indeed, very easy. +1

      – marmot
      17 mins ago

















    Indeed, very easy. +1

    – marmot
    17 mins ago





    Indeed, very easy. +1

    – marmot
    17 mins ago











    1














    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




























      1














      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


























        1












        1








        1







        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










        answered 52 mins ago









        Ulrich DiezUlrich Diez

        5,470619




        5,470619






















            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

            Contact image not getting when fetch all contact list from iPhone by CNContact

            count number of partitions of a set with n elements into k subsets

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks