Non-italic (roman) subscripts in math mode
up vote
3
down vote
favorite
Is there a way to set indices (subscripts) to non-italic globally? I'm aware of the case by case
X_{text{text goes here}}
But I'm having to change that across a whole document is becoming a pain.
math-mode subscripts
New contributor
Andy Grey is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
|
show 2 more comments
up vote
3
down vote
favorite
Is there a way to set indices (subscripts) to non-italic globally? I'm aware of the case by case
X_{text{text goes here}}
But I'm having to change that across a whole document is becoming a pain.
math-mode subscripts
New contributor
Andy Grey is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
The following is not an answer but a remark. Withtextthe font will change with the surrounding text, so it'll e.g. be italic inside a theorem environment. This is probably undesirable, so I would recommend usingtextnormalinstead.
– Circumscribe
7 hours ago
It is possible to overload_to do this, but it might break things. Might definingnewcommand*subtxt[1]{_{textnormal{#1}}}and doing a search-and-replace for_→subtxtbe a good alternative?
– Circumscribe
7 hours ago
see e.g. tex.stackexchange.com/a/228606/2388
– Ulrike Fischer
7 hours ago
@Circumscribe thanks! I'll give that a try!
– Andy Grey
7 hours ago
@AndyGrey: make sure to include a space insubtxt(at the end) if your document contains things likeX_awithout{}.
– Circumscribe
7 hours ago
|
show 2 more comments
up vote
3
down vote
favorite
up vote
3
down vote
favorite
Is there a way to set indices (subscripts) to non-italic globally? I'm aware of the case by case
X_{text{text goes here}}
But I'm having to change that across a whole document is becoming a pain.
math-mode subscripts
New contributor
Andy Grey is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Is there a way to set indices (subscripts) to non-italic globally? I'm aware of the case by case
X_{text{text goes here}}
But I'm having to change that across a whole document is becoming a pain.
math-mode subscripts
math-mode subscripts
New contributor
Andy Grey is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Andy Grey is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 5 hours ago
Mico
272k30369756
272k30369756
New contributor
Andy Grey is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 7 hours ago
Andy Grey
283
283
New contributor
Andy Grey is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Andy Grey is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Andy Grey is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
The following is not an answer but a remark. Withtextthe font will change with the surrounding text, so it'll e.g. be italic inside a theorem environment. This is probably undesirable, so I would recommend usingtextnormalinstead.
– Circumscribe
7 hours ago
It is possible to overload_to do this, but it might break things. Might definingnewcommand*subtxt[1]{_{textnormal{#1}}}and doing a search-and-replace for_→subtxtbe a good alternative?
– Circumscribe
7 hours ago
see e.g. tex.stackexchange.com/a/228606/2388
– Ulrike Fischer
7 hours ago
@Circumscribe thanks! I'll give that a try!
– Andy Grey
7 hours ago
@AndyGrey: make sure to include a space insubtxt(at the end) if your document contains things likeX_awithout{}.
– Circumscribe
7 hours ago
|
show 2 more comments
The following is not an answer but a remark. Withtextthe font will change with the surrounding text, so it'll e.g. be italic inside a theorem environment. This is probably undesirable, so I would recommend usingtextnormalinstead.
– Circumscribe
7 hours ago
It is possible to overload_to do this, but it might break things. Might definingnewcommand*subtxt[1]{_{textnormal{#1}}}and doing a search-and-replace for_→subtxtbe a good alternative?
– Circumscribe
7 hours ago
see e.g. tex.stackexchange.com/a/228606/2388
– Ulrike Fischer
7 hours ago
@Circumscribe thanks! I'll give that a try!
– Andy Grey
7 hours ago
@AndyGrey: make sure to include a space insubtxt(at the end) if your document contains things likeX_awithout{}.
– Circumscribe
7 hours ago
The following is not an answer but a remark. With
text the font will change with the surrounding text, so it'll e.g. be italic inside a theorem environment. This is probably undesirable, so I would recommend using textnormal instead.– Circumscribe
7 hours ago
The following is not an answer but a remark. With
text the font will change with the surrounding text, so it'll e.g. be italic inside a theorem environment. This is probably undesirable, so I would recommend using textnormal instead.– Circumscribe
7 hours ago
It is possible to overload
_ to do this, but it might break things. Might defining newcommand*subtxt[1]{_{textnormal{#1}}} and doing a search-and-replace for _ → subtxt be a good alternative?– Circumscribe
7 hours ago
It is possible to overload
_ to do this, but it might break things. Might defining newcommand*subtxt[1]{_{textnormal{#1}}} and doing a search-and-replace for _ → subtxt be a good alternative?– Circumscribe
7 hours ago
see e.g. tex.stackexchange.com/a/228606/2388
– Ulrike Fischer
7 hours ago
see e.g. tex.stackexchange.com/a/228606/2388
– Ulrike Fischer
7 hours ago
@Circumscribe thanks! I'll give that a try!
– Andy Grey
7 hours ago
@Circumscribe thanks! I'll give that a try!
– Andy Grey
7 hours ago
@AndyGrey: make sure to include a space in
subtxt (at the end) if your document contains things like X_a without {}.– Circumscribe
7 hours ago
@AndyGrey: make sure to include a space in
subtxt (at the end) if your document contains things like X_a without {}.– Circumscribe
7 hours ago
|
show 2 more comments
4 Answers
4
active
oldest
votes
up vote
6
down vote
It is possible to overload _ to set all subscripts in roman type, but that seems like a bad idea since it might break something unexpected.
You may instead want to consider defining a macro that produces an upright subscript. I've defined such a macro (subtxt) below.
Since it seems unlikely that you'll need underscores in math mode, I've also redefined _ to expand to subtxt whenever it is used in math mode (and to produce an underscore otherwise, like normal).
documentclass{article}
usepackage{amsmath} %% <- necessary for correct scaling of subscripts
begin{document}
newcommand*subtxt[1]{_{textnormal{#1}}}
DeclareRobustCommand_{ifmmodeexpandaftersubtxtelsetextunderscorefi}
[
X_i + Xsubtxt{i} + X_i + X_{text goes here}
]
end{document}

Notes:
I'm using
textnormalinstead oftextbecause the font of subscripts created with the latter command changes based on the surrounding text. You for instance probably wouldn't want all of your subscripts inside theorem environments to be in italics. See e.g. this answer for more info.I'm using
DeclareRobustCommandto redefine_because the original version of this macro is also defined like that. It isn't too important, but more information can be found here.
Unless you're using underscores for some other purpose in your document, you can now do a search-and-replace to change every _ into _.
add a comment |
up vote
4
down vote

documentclass{article}
begin{document}
sbox0{$$}
scriptfont1=scriptfont0
$X_{abc}+y_{max}$
end{document}
Note this affects all math uses of the script size font not just subscripts.
Would that work for equation, align and other environments?
– Andy Grey
6 hours ago
@AndyGrey yes..
– David Carlisle
6 hours ago
2
What kind of sorcery issbox0{$$}for? Just loading the math fonts?
– Werner
4 hours ago
1
@Werner latex delays finalizing the math setup until the first use of math at each font size, so that you can switch math fonts. actually for basic math atnormalsizeit probably makes no difference as things are pre-loaded, but it's a good habit to make sure...
– David Carlisle
4 hours ago
1
$x_{max}$ worksfootnote{But $X_{max}$ doesn't} and what about $x_{max}$?
– egreg
3 hours ago
|
show 3 more comments
up vote
3
down vote
Here's a LuaLaTeX-based solution. Subscripts enclosed by curly braces are typeset with upright ("roman") letters, as long as there's no space between the _ (underscore) character and the material enclosed in curly braces. If a subscript term is not enclosed in curly braces, e.g., $x_i$, it's not processed by the Lua code.
If, for some reason, you do not want to the Lua function to operate on a subscript term encased in curly braces, just make sure that there are one or more spaces between _ and the subscript term. An obvious reason for wanting to suspend operation of the Lua function would be the fact that the subscript term contains math material which should be processed in math mode.
To activate operations, issue the instruction upsubOn. To terminate them completely, execute upsubOff.

% !TEX TS-program = lualatex
documentclass{article}
usepackage{amsmath,unicode-math}
usepackage{luacode}
%% Lua-side code:
begin{luacode}
function sub_up ( s )
return ( s:gsub ( "_(%b{})" , "_{\textnormal%1}" ) )
end
end{luacode}
%% LaTeX-side code:
newcommandupsubOn{directlua{luatexbase.add_to_callback(
"process_input_buffer" , sub_up , "subup" )}}
newcommandupsubOff{directlua{luatexbase.remove_from_callback(
"process_input_buffer" , "subup" )}}
AtBeginDocument{upsubOn} % activate the Lua function by default
begin{document}
$X_{text goes here}$quad $x_ {ab cd}$quad $x_ {i_j},x_k^u$
upsubOff
$X_{text goes here}$quad $x_ {ab cd}$quad $x_ {i_j},x_k^u$
end{document}
add a comment |
up vote
3
down vote
I suggest to use a different character for those subscripts. One way could be to use ? that's very rarely used in math mode. Another uses ↓ (maybe you can find a way to type it easily).
documentclass{article}
usepackage{amsmath}
usepackage{newunicodechar} % for using ↓
% the main command
newcommand{uprightsubscript}[1]{_{textnormal{#1}}}
% this sets up the use of ?
begingrouplccode`~=`?lowercase{endgrouplet~}uprightsubscript
AtBeginDocument{mathcode`?="8000 }
% this sets up the use of ↓
newunicodechar{↓}{uprightsubscript}
textheight=2cm % just for making a smaller picture
begin{document}
$x?{max}$ worksfootnote{Also here $x?{max}$} and again $x?{max}$?
$x↓{max}$ worksfootnote{Also here $x↓{max}$} and again $x↓{max}$?
end{document}

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
});
}
});
Andy Grey 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%2f466411%2fnon-italic-roman-subscripts-in-math-mode%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
up vote
6
down vote
It is possible to overload _ to set all subscripts in roman type, but that seems like a bad idea since it might break something unexpected.
You may instead want to consider defining a macro that produces an upright subscript. I've defined such a macro (subtxt) below.
Since it seems unlikely that you'll need underscores in math mode, I've also redefined _ to expand to subtxt whenever it is used in math mode (and to produce an underscore otherwise, like normal).
documentclass{article}
usepackage{amsmath} %% <- necessary for correct scaling of subscripts
begin{document}
newcommand*subtxt[1]{_{textnormal{#1}}}
DeclareRobustCommand_{ifmmodeexpandaftersubtxtelsetextunderscorefi}
[
X_i + Xsubtxt{i} + X_i + X_{text goes here}
]
end{document}

Notes:
I'm using
textnormalinstead oftextbecause the font of subscripts created with the latter command changes based on the surrounding text. You for instance probably wouldn't want all of your subscripts inside theorem environments to be in italics. See e.g. this answer for more info.I'm using
DeclareRobustCommandto redefine_because the original version of this macro is also defined like that. It isn't too important, but more information can be found here.
Unless you're using underscores for some other purpose in your document, you can now do a search-and-replace to change every _ into _.
add a comment |
up vote
6
down vote
It is possible to overload _ to set all subscripts in roman type, but that seems like a bad idea since it might break something unexpected.
You may instead want to consider defining a macro that produces an upright subscript. I've defined such a macro (subtxt) below.
Since it seems unlikely that you'll need underscores in math mode, I've also redefined _ to expand to subtxt whenever it is used in math mode (and to produce an underscore otherwise, like normal).
documentclass{article}
usepackage{amsmath} %% <- necessary for correct scaling of subscripts
begin{document}
newcommand*subtxt[1]{_{textnormal{#1}}}
DeclareRobustCommand_{ifmmodeexpandaftersubtxtelsetextunderscorefi}
[
X_i + Xsubtxt{i} + X_i + X_{text goes here}
]
end{document}

Notes:
I'm using
textnormalinstead oftextbecause the font of subscripts created with the latter command changes based on the surrounding text. You for instance probably wouldn't want all of your subscripts inside theorem environments to be in italics. See e.g. this answer for more info.I'm using
DeclareRobustCommandto redefine_because the original version of this macro is also defined like that. It isn't too important, but more information can be found here.
Unless you're using underscores for some other purpose in your document, you can now do a search-and-replace to change every _ into _.
add a comment |
up vote
6
down vote
up vote
6
down vote
It is possible to overload _ to set all subscripts in roman type, but that seems like a bad idea since it might break something unexpected.
You may instead want to consider defining a macro that produces an upright subscript. I've defined such a macro (subtxt) below.
Since it seems unlikely that you'll need underscores in math mode, I've also redefined _ to expand to subtxt whenever it is used in math mode (and to produce an underscore otherwise, like normal).
documentclass{article}
usepackage{amsmath} %% <- necessary for correct scaling of subscripts
begin{document}
newcommand*subtxt[1]{_{textnormal{#1}}}
DeclareRobustCommand_{ifmmodeexpandaftersubtxtelsetextunderscorefi}
[
X_i + Xsubtxt{i} + X_i + X_{text goes here}
]
end{document}

Notes:
I'm using
textnormalinstead oftextbecause the font of subscripts created with the latter command changes based on the surrounding text. You for instance probably wouldn't want all of your subscripts inside theorem environments to be in italics. See e.g. this answer for more info.I'm using
DeclareRobustCommandto redefine_because the original version of this macro is also defined like that. It isn't too important, but more information can be found here.
Unless you're using underscores for some other purpose in your document, you can now do a search-and-replace to change every _ into _.
It is possible to overload _ to set all subscripts in roman type, but that seems like a bad idea since it might break something unexpected.
You may instead want to consider defining a macro that produces an upright subscript. I've defined such a macro (subtxt) below.
Since it seems unlikely that you'll need underscores in math mode, I've also redefined _ to expand to subtxt whenever it is used in math mode (and to produce an underscore otherwise, like normal).
documentclass{article}
usepackage{amsmath} %% <- necessary for correct scaling of subscripts
begin{document}
newcommand*subtxt[1]{_{textnormal{#1}}}
DeclareRobustCommand_{ifmmodeexpandaftersubtxtelsetextunderscorefi}
[
X_i + Xsubtxt{i} + X_i + X_{text goes here}
]
end{document}

Notes:
I'm using
textnormalinstead oftextbecause the font of subscripts created with the latter command changes based on the surrounding text. You for instance probably wouldn't want all of your subscripts inside theorem environments to be in italics. See e.g. this answer for more info.I'm using
DeclareRobustCommandto redefine_because the original version of this macro is also defined like that. It isn't too important, but more information can be found here.
Unless you're using underscores for some other purpose in your document, you can now do a search-and-replace to change every _ into _.
edited 3 hours ago
answered 5 hours ago
Circumscribe
4,3971430
4,3971430
add a comment |
add a comment |
up vote
4
down vote

documentclass{article}
begin{document}
sbox0{$$}
scriptfont1=scriptfont0
$X_{abc}+y_{max}$
end{document}
Note this affects all math uses of the script size font not just subscripts.
Would that work for equation, align and other environments?
– Andy Grey
6 hours ago
@AndyGrey yes..
– David Carlisle
6 hours ago
2
What kind of sorcery issbox0{$$}for? Just loading the math fonts?
– Werner
4 hours ago
1
@Werner latex delays finalizing the math setup until the first use of math at each font size, so that you can switch math fonts. actually for basic math atnormalsizeit probably makes no difference as things are pre-loaded, but it's a good habit to make sure...
– David Carlisle
4 hours ago
1
$x_{max}$ worksfootnote{But $X_{max}$ doesn't} and what about $x_{max}$?
– egreg
3 hours ago
|
show 3 more comments
up vote
4
down vote

documentclass{article}
begin{document}
sbox0{$$}
scriptfont1=scriptfont0
$X_{abc}+y_{max}$
end{document}
Note this affects all math uses of the script size font not just subscripts.
Would that work for equation, align and other environments?
– Andy Grey
6 hours ago
@AndyGrey yes..
– David Carlisle
6 hours ago
2
What kind of sorcery issbox0{$$}for? Just loading the math fonts?
– Werner
4 hours ago
1
@Werner latex delays finalizing the math setup until the first use of math at each font size, so that you can switch math fonts. actually for basic math atnormalsizeit probably makes no difference as things are pre-loaded, but it's a good habit to make sure...
– David Carlisle
4 hours ago
1
$x_{max}$ worksfootnote{But $X_{max}$ doesn't} and what about $x_{max}$?
– egreg
3 hours ago
|
show 3 more comments
up vote
4
down vote
up vote
4
down vote

documentclass{article}
begin{document}
sbox0{$$}
scriptfont1=scriptfont0
$X_{abc}+y_{max}$
end{document}
Note this affects all math uses of the script size font not just subscripts.

documentclass{article}
begin{document}
sbox0{$$}
scriptfont1=scriptfont0
$X_{abc}+y_{max}$
end{document}
Note this affects all math uses of the script size font not just subscripts.
answered 6 hours ago
David Carlisle
481k3811121848
481k3811121848
Would that work for equation, align and other environments?
– Andy Grey
6 hours ago
@AndyGrey yes..
– David Carlisle
6 hours ago
2
What kind of sorcery issbox0{$$}for? Just loading the math fonts?
– Werner
4 hours ago
1
@Werner latex delays finalizing the math setup until the first use of math at each font size, so that you can switch math fonts. actually for basic math atnormalsizeit probably makes no difference as things are pre-loaded, but it's a good habit to make sure...
– David Carlisle
4 hours ago
1
$x_{max}$ worksfootnote{But $X_{max}$ doesn't} and what about $x_{max}$?
– egreg
3 hours ago
|
show 3 more comments
Would that work for equation, align and other environments?
– Andy Grey
6 hours ago
@AndyGrey yes..
– David Carlisle
6 hours ago
2
What kind of sorcery issbox0{$$}for? Just loading the math fonts?
– Werner
4 hours ago
1
@Werner latex delays finalizing the math setup until the first use of math at each font size, so that you can switch math fonts. actually for basic math atnormalsizeit probably makes no difference as things are pre-loaded, but it's a good habit to make sure...
– David Carlisle
4 hours ago
1
$x_{max}$ worksfootnote{But $X_{max}$ doesn't} and what about $x_{max}$?
– egreg
3 hours ago
Would that work for equation, align and other environments?
– Andy Grey
6 hours ago
Would that work for equation, align and other environments?
– Andy Grey
6 hours ago
@AndyGrey yes..
– David Carlisle
6 hours ago
@AndyGrey yes..
– David Carlisle
6 hours ago
2
2
What kind of sorcery is
sbox0{$$} for? Just loading the math fonts?– Werner
4 hours ago
What kind of sorcery is
sbox0{$$} for? Just loading the math fonts?– Werner
4 hours ago
1
1
@Werner latex delays finalizing the math setup until the first use of math at each font size, so that you can switch math fonts. actually for basic math at
normalsize it probably makes no difference as things are pre-loaded, but it's a good habit to make sure...– David Carlisle
4 hours ago
@Werner latex delays finalizing the math setup until the first use of math at each font size, so that you can switch math fonts. actually for basic math at
normalsize it probably makes no difference as things are pre-loaded, but it's a good habit to make sure...– David Carlisle
4 hours ago
1
1
$x_{max}$ worksfootnote{But $X_{max}$ doesn't} and what about $x_{max}$?– egreg
3 hours ago
$x_{max}$ worksfootnote{But $X_{max}$ doesn't} and what about $x_{max}$?– egreg
3 hours ago
|
show 3 more comments
up vote
3
down vote
Here's a LuaLaTeX-based solution. Subscripts enclosed by curly braces are typeset with upright ("roman") letters, as long as there's no space between the _ (underscore) character and the material enclosed in curly braces. If a subscript term is not enclosed in curly braces, e.g., $x_i$, it's not processed by the Lua code.
If, for some reason, you do not want to the Lua function to operate on a subscript term encased in curly braces, just make sure that there are one or more spaces between _ and the subscript term. An obvious reason for wanting to suspend operation of the Lua function would be the fact that the subscript term contains math material which should be processed in math mode.
To activate operations, issue the instruction upsubOn. To terminate them completely, execute upsubOff.

% !TEX TS-program = lualatex
documentclass{article}
usepackage{amsmath,unicode-math}
usepackage{luacode}
%% Lua-side code:
begin{luacode}
function sub_up ( s )
return ( s:gsub ( "_(%b{})" , "_{\textnormal%1}" ) )
end
end{luacode}
%% LaTeX-side code:
newcommandupsubOn{directlua{luatexbase.add_to_callback(
"process_input_buffer" , sub_up , "subup" )}}
newcommandupsubOff{directlua{luatexbase.remove_from_callback(
"process_input_buffer" , "subup" )}}
AtBeginDocument{upsubOn} % activate the Lua function by default
begin{document}
$X_{text goes here}$quad $x_ {ab cd}$quad $x_ {i_j},x_k^u$
upsubOff
$X_{text goes here}$quad $x_ {ab cd}$quad $x_ {i_j},x_k^u$
end{document}
add a comment |
up vote
3
down vote
Here's a LuaLaTeX-based solution. Subscripts enclosed by curly braces are typeset with upright ("roman") letters, as long as there's no space between the _ (underscore) character and the material enclosed in curly braces. If a subscript term is not enclosed in curly braces, e.g., $x_i$, it's not processed by the Lua code.
If, for some reason, you do not want to the Lua function to operate on a subscript term encased in curly braces, just make sure that there are one or more spaces between _ and the subscript term. An obvious reason for wanting to suspend operation of the Lua function would be the fact that the subscript term contains math material which should be processed in math mode.
To activate operations, issue the instruction upsubOn. To terminate them completely, execute upsubOff.

% !TEX TS-program = lualatex
documentclass{article}
usepackage{amsmath,unicode-math}
usepackage{luacode}
%% Lua-side code:
begin{luacode}
function sub_up ( s )
return ( s:gsub ( "_(%b{})" , "_{\textnormal%1}" ) )
end
end{luacode}
%% LaTeX-side code:
newcommandupsubOn{directlua{luatexbase.add_to_callback(
"process_input_buffer" , sub_up , "subup" )}}
newcommandupsubOff{directlua{luatexbase.remove_from_callback(
"process_input_buffer" , "subup" )}}
AtBeginDocument{upsubOn} % activate the Lua function by default
begin{document}
$X_{text goes here}$quad $x_ {ab cd}$quad $x_ {i_j},x_k^u$
upsubOff
$X_{text goes here}$quad $x_ {ab cd}$quad $x_ {i_j},x_k^u$
end{document}
add a comment |
up vote
3
down vote
up vote
3
down vote
Here's a LuaLaTeX-based solution. Subscripts enclosed by curly braces are typeset with upright ("roman") letters, as long as there's no space between the _ (underscore) character and the material enclosed in curly braces. If a subscript term is not enclosed in curly braces, e.g., $x_i$, it's not processed by the Lua code.
If, for some reason, you do not want to the Lua function to operate on a subscript term encased in curly braces, just make sure that there are one or more spaces between _ and the subscript term. An obvious reason for wanting to suspend operation of the Lua function would be the fact that the subscript term contains math material which should be processed in math mode.
To activate operations, issue the instruction upsubOn. To terminate them completely, execute upsubOff.

% !TEX TS-program = lualatex
documentclass{article}
usepackage{amsmath,unicode-math}
usepackage{luacode}
%% Lua-side code:
begin{luacode}
function sub_up ( s )
return ( s:gsub ( "_(%b{})" , "_{\textnormal%1}" ) )
end
end{luacode}
%% LaTeX-side code:
newcommandupsubOn{directlua{luatexbase.add_to_callback(
"process_input_buffer" , sub_up , "subup" )}}
newcommandupsubOff{directlua{luatexbase.remove_from_callback(
"process_input_buffer" , "subup" )}}
AtBeginDocument{upsubOn} % activate the Lua function by default
begin{document}
$X_{text goes here}$quad $x_ {ab cd}$quad $x_ {i_j},x_k^u$
upsubOff
$X_{text goes here}$quad $x_ {ab cd}$quad $x_ {i_j},x_k^u$
end{document}
Here's a LuaLaTeX-based solution. Subscripts enclosed by curly braces are typeset with upright ("roman") letters, as long as there's no space between the _ (underscore) character and the material enclosed in curly braces. If a subscript term is not enclosed in curly braces, e.g., $x_i$, it's not processed by the Lua code.
If, for some reason, you do not want to the Lua function to operate on a subscript term encased in curly braces, just make sure that there are one or more spaces between _ and the subscript term. An obvious reason for wanting to suspend operation of the Lua function would be the fact that the subscript term contains math material which should be processed in math mode.
To activate operations, issue the instruction upsubOn. To terminate them completely, execute upsubOff.

% !TEX TS-program = lualatex
documentclass{article}
usepackage{amsmath,unicode-math}
usepackage{luacode}
%% Lua-side code:
begin{luacode}
function sub_up ( s )
return ( s:gsub ( "_(%b{})" , "_{\textnormal%1}" ) )
end
end{luacode}
%% LaTeX-side code:
newcommandupsubOn{directlua{luatexbase.add_to_callback(
"process_input_buffer" , sub_up , "subup" )}}
newcommandupsubOff{directlua{luatexbase.remove_from_callback(
"process_input_buffer" , "subup" )}}
AtBeginDocument{upsubOn} % activate the Lua function by default
begin{document}
$X_{text goes here}$quad $x_ {ab cd}$quad $x_ {i_j},x_k^u$
upsubOff
$X_{text goes here}$quad $x_ {ab cd}$quad $x_ {i_j},x_k^u$
end{document}
answered 4 hours ago
Mico
272k30369756
272k30369756
add a comment |
add a comment |
up vote
3
down vote
I suggest to use a different character for those subscripts. One way could be to use ? that's very rarely used in math mode. Another uses ↓ (maybe you can find a way to type it easily).
documentclass{article}
usepackage{amsmath}
usepackage{newunicodechar} % for using ↓
% the main command
newcommand{uprightsubscript}[1]{_{textnormal{#1}}}
% this sets up the use of ?
begingrouplccode`~=`?lowercase{endgrouplet~}uprightsubscript
AtBeginDocument{mathcode`?="8000 }
% this sets up the use of ↓
newunicodechar{↓}{uprightsubscript}
textheight=2cm % just for making a smaller picture
begin{document}
$x?{max}$ worksfootnote{Also here $x?{max}$} and again $x?{max}$?
$x↓{max}$ worksfootnote{Also here $x↓{max}$} and again $x↓{max}$?
end{document}

add a comment |
up vote
3
down vote
I suggest to use a different character for those subscripts. One way could be to use ? that's very rarely used in math mode. Another uses ↓ (maybe you can find a way to type it easily).
documentclass{article}
usepackage{amsmath}
usepackage{newunicodechar} % for using ↓
% the main command
newcommand{uprightsubscript}[1]{_{textnormal{#1}}}
% this sets up the use of ?
begingrouplccode`~=`?lowercase{endgrouplet~}uprightsubscript
AtBeginDocument{mathcode`?="8000 }
% this sets up the use of ↓
newunicodechar{↓}{uprightsubscript}
textheight=2cm % just for making a smaller picture
begin{document}
$x?{max}$ worksfootnote{Also here $x?{max}$} and again $x?{max}$?
$x↓{max}$ worksfootnote{Also here $x↓{max}$} and again $x↓{max}$?
end{document}

add a comment |
up vote
3
down vote
up vote
3
down vote
I suggest to use a different character for those subscripts. One way could be to use ? that's very rarely used in math mode. Another uses ↓ (maybe you can find a way to type it easily).
documentclass{article}
usepackage{amsmath}
usepackage{newunicodechar} % for using ↓
% the main command
newcommand{uprightsubscript}[1]{_{textnormal{#1}}}
% this sets up the use of ?
begingrouplccode`~=`?lowercase{endgrouplet~}uprightsubscript
AtBeginDocument{mathcode`?="8000 }
% this sets up the use of ↓
newunicodechar{↓}{uprightsubscript}
textheight=2cm % just for making a smaller picture
begin{document}
$x?{max}$ worksfootnote{Also here $x?{max}$} and again $x?{max}$?
$x↓{max}$ worksfootnote{Also here $x↓{max}$} and again $x↓{max}$?
end{document}

I suggest to use a different character for those subscripts. One way could be to use ? that's very rarely used in math mode. Another uses ↓ (maybe you can find a way to type it easily).
documentclass{article}
usepackage{amsmath}
usepackage{newunicodechar} % for using ↓
% the main command
newcommand{uprightsubscript}[1]{_{textnormal{#1}}}
% this sets up the use of ?
begingrouplccode`~=`?lowercase{endgrouplet~}uprightsubscript
AtBeginDocument{mathcode`?="8000 }
% this sets up the use of ↓
newunicodechar{↓}{uprightsubscript}
textheight=2cm % just for making a smaller picture
begin{document}
$x?{max}$ worksfootnote{Also here $x?{max}$} and again $x?{max}$?
$x↓{max}$ worksfootnote{Also here $x↓{max}$} and again $x↓{max}$?
end{document}

answered 3 hours ago
egreg
705k8618773157
705k8618773157
add a comment |
add a comment |
Andy Grey is a new contributor. Be nice, and check out our Code of Conduct.
Andy Grey is a new contributor. Be nice, and check out our Code of Conduct.
Andy Grey is a new contributor. Be nice, and check out our Code of Conduct.
Andy Grey 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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f466411%2fnon-italic-roman-subscripts-in-math-mode%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
The following is not an answer but a remark. With
textthe font will change with the surrounding text, so it'll e.g. be italic inside a theorem environment. This is probably undesirable, so I would recommend usingtextnormalinstead.– Circumscribe
7 hours ago
It is possible to overload
_to do this, but it might break things. Might definingnewcommand*subtxt[1]{_{textnormal{#1}}}and doing a search-and-replace for_→subtxtbe a good alternative?– Circumscribe
7 hours ago
see e.g. tex.stackexchange.com/a/228606/2388
– Ulrike Fischer
7 hours ago
@Circumscribe thanks! I'll give that a try!
– Andy Grey
7 hours ago
@AndyGrey: make sure to include a space in
subtxt(at the end) if your document contains things likeX_awithout{}.– Circumscribe
7 hours ago