Typing CO_2 easily
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
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.
add a comment |
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
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 usenewcommand{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
add a comment |
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
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
chemistry
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.
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 usenewcommand{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
add a comment |
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 usenewcommand{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
add a comment |
3 Answers
3
active
oldest
votes
You want easy?
documentclass{article}
usepackage{chemformula}
begin{document}
ch{CO2}
end{document}
Indeed, very easy. +1
– marmot
9 hours ago
4
For completeness, you might mention alsomhchem
– egreg
4 hours ago
add a comment |
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}

(I elaborated on the name-macro in my answer to the question "How to implement expandbefore, similarly to expandafter?".)
add a comment |
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.

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.
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
You want easy?
documentclass{article}
usepackage{chemformula}
begin{document}
ch{CO2}
end{document}
Indeed, very easy. +1
– marmot
9 hours ago
4
For completeness, you might mention alsomhchem
– egreg
4 hours ago
add a comment |
You want easy?
documentclass{article}
usepackage{chemformula}
begin{document}
ch{CO2}
end{document}
Indeed, very easy. +1
– marmot
9 hours ago
4
For completeness, you might mention alsomhchem
– egreg
4 hours ago
add a comment |
You want easy?
documentclass{article}
usepackage{chemformula}
begin{document}
ch{CO2}
end{document}
You want easy?
documentclass{article}
usepackage{chemformula}
begin{document}
ch{CO2}
end{document}
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 alsomhchem
– egreg
4 hours ago
add a comment |
Indeed, very easy. +1
– marmot
9 hours ago
4
For completeness, you might mention alsomhchem
– 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
add a comment |
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}

(I elaborated on the name-macro in my answer to the question "How to implement expandbefore, similarly to expandafter?".)
add a comment |
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}

(I elaborated on the name-macro in my answer to the question "How to implement expandbefore, similarly to expandafter?".)
add a comment |
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}

(I elaborated on the name-macro in my answer to the question "How to implement expandbefore, similarly to expandafter?".)
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}

(I elaborated on the name-macro in my answer to the question "How to implement expandbefore, similarly to expandafter?".)
edited 4 hours ago
answered 10 hours ago
Ulrich DiezUlrich Diez
5,500619
5,500619
add a comment |
add a comment |
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.

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.
add a comment |
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.

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.
add a comment |
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.

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.
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.

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.
answered 17 mins ago
Sandy GSandy G
3,4621425
3,4621425
add a comment |
add a comment |
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.
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 usenewcommand{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