Change the mathmode font

fontsmath-mode

I'm looking for a way to get the textfont (lmodern for my case) into mathmode as in 2) but without using \text{} each time I need to write text in math mode. How do we change the font of mathmode in such a way?

enter image description here

EDIT :
I put an image to be more explicit, I hope you understand better what I mean. It's simple in fact, I don't want the standard mathmode font at all whether it is between $…$ or in an equation environment or anywhere else. I don't want to use \text{} command each time I need to write something on a line in math mode.

enter image description here

Best Answer

If you're willing and able to use LuaLaTeX to compile your document, the following solution may (should?) be of interest to you. It defines a Lua function which, if activated, renders subscript and superscript terms with \mathrm if there is no whitespace between the _ and ^ characters and the sub/super-script arguments.

The solution also provides two utility macros, named \SubSupToMathrmOn and \SubSupToMathrmOff, respectively, to activate and deactivate the Lua function. By "activate", I mean "assign the Lua function to LuaTeX's process_input_buffer callback so that it functions as a preprocessor."

enter image description here

If you want to render a subscript or superscript term in upright letters without deactivating the Lua function, just make sure to leave whitespace immediately after the _ and ^ characters.

% !TEX TS-program = lualatex
% see also https://tex.stackexchange.com/a/630382/5001

\documentclass{article}
\usepackage{luacode} % for 'luacode' environment
\begin{luacode} 
  -- Define the Lua function that does all of the work:
  function subsup2mathrm ( s )
    s = s:gsub ( "_(%b{})"  , "_{\\mathrm%1}" )
    s = s:gsub ( "_(%a)"    , "_{\\mathrm{%1}}" )
    s = s:gsub ( "%^(%b{})" , "^{\\mathrm%1}" )
    s = s:gsub ( "%^(%a)"   , "^{\\mathrm{%1}}" )
    return s
  end
\end{luacode}

%% LaTeX utility macros to activate and deactivate the Lua function:
\newcommand\SubSupToMathrmOn{\directlua{luatexbase.add_to_callback ( 
   "process_input_buffer" , subsup2mathrm , "subsup2mathrm" )}}
\newcommand\SubSupToMathrmOff{\directlua{luatexbase.remove_from_callback ( 
   "process_input_buffer" , "subsup2mathrm" )}}

\begin{document}
$u_v^w$ $\mu_{something}^{anything}$ % Lua function isn't activated yet

\medskip
\SubSupToMathrmOn % now activate the Lua function
$u_v^w$ $\mu_{something} ^{anything}$ \quad $u_ v ^ w$
\end{document}