The lmodern
package removes many of the settings of the eulermath
option and you remain in a very unstable state.
Load eulervm
later than lmodern
:
\documentclass{article}
\usepackage[nochapters]{classicthesis}
\usepackage{lmodern}
\usepackage[euler-digits]{eulervm}
\begin{document}
Some text for seeing what happens
\[
(x+2)(x-5)
\]
\end{document}
I don't think that this is a good idea, typographically, though.
Don't use $$
in LaTeX, see Why is \[ ... \] preferable to $$ ... $$?
(I rewrote the code to make it consist of three separate files: A driver tex file that produces the screenshot; a style file (loaded by the driver file) that sets up the main user macro, called \prettymath
; and a lua file (loaded from the style file via a dofile
instruction) that performs the actual work.)
The following LuaLaTeX-based solution should not be viewed as a full-blown tool. For now, it's mainly intended to showcase the usefulness and versatility of some of Lua's string functions for the purpose of tackling the problem at hand.
It processes **
exponential notation, deletes single *
instances, converts the roman-letter representations of selected lowercase Greek letters (e.g., alpha
and pi
) to their "native" Greek-character glyphs, and pretty-prints integral expressions, selected three-letter mathop functions (sin
, cos
, tan
, and det
-- it should be straightforward to extend this list) as well as square roots and fractions. It can handle nested fractions and square roots. Naturally, this list is far from complete. Hopefully, the code shown below is reasonably self-explanatory so that (I hope) it's not too difficult to handle other cases.
The driver file:
% !TeX program = lualatex
% Test file to check out operation of 'cmath2latex' package
\documentclass{article}
\usepackage{cmath2latex}
% set up three test strings
\newcommand\mystringa{sqrt(3**(x)*(a*sin(exp(theta))
*cos(2*pi)) / (det (A)*tan(gamma)) ) }
\newcommand\mystringb{3*c/(a+2), 1/pi, pi/2, 2*pi/3, a/b,
x/(y+z), (x+y)/z, (a/b)/(c/d)}
\newcommand\mystringc{sqrt( sqrt(sqrt(256))), Integral
(sqrt((2**(y))/(y)) , y )}
\begin{document}
\everymath{\displaystyle} % just for this example
\verb&sqrt(3**(x)*(a*sin(exp(theta))*cos(2*pi)) / (det (A)*tan(gamma)) )&
\prettymath{\mystringa}
\bigskip
\verb&3*c/(a+2), 1/pi, pi/2, 2*pi/3, a/b, x/(y+z), (x+y)/z, (a/b)/(c/d)&
\prettymath{\mystringb}
\bigskip
\verb&sqrt( sqrt(sqrt(256))), Integral (sqrt((2**(y))/y) , y )&
\prettymath{\mystringc}
\end{document}
The style file; I suggest you call it cmath2latex.sty
:
% !TeX program = lualatex
\ProvidesPackage{cmath2latex}[2017/01/09, version 0.01]
\usepackage{luacode} % for "\luastring" macro
\usepackage{amsmath} % for "\ensuremath" macro
%% Load the Lua code
\directlua{dofile("cmath2latex.lua")}
%% The LaTeX macro "\prettymath" calls the Lua function
%% "prettymath" and outputs the result in math mode
\newcommand\prettymath[1]{\ensuremath{\directlua{%
tex.sprint(prettymath(\luastring{#1}))}}}
The file that contains the Lua code; I suggest you call it "cmath2latex.lua":
-- cmath2latex.lua
-- This file is loaded by cmath2latex.sty via a dofile call
-- "prettymath" is called by the "\prettymath" LaTeX macro
-- (which is defined in "prettymath.sty")
function prettymath ( s )
-- exponential notation
s = s:gsub ( "%*%*%s-(%b())" , do_exp )
-- multiplication: delete all single instances of "*"
s = s:gsub ( "%*" , "" )
-- integrals
s = s:gsub ( "Integral%s-(%b())", do_integral )
-- some Greek letters
s = s:gsub ( "alpha" , do_gr_letter )
s = s:gsub ( "beta" , do_gr_letter )
s = s:gsub ( "gamma" , do_gr_letter )
s = s:gsub ( "Gamma" , do_gr_letter )
s = s:gsub ( "delta" , do_gr_letter )
s = s:gsub ( "Delta" , do_gr_letter )
s = s:gsub ( "theta" , do_gr_letter )
s = s:gsub ( "pi" , do_gr_letter )
s = s:gsub ( "Pi" , do_gr_letter )
-- some pre-defined 3-letter operators w/ args in parens
s = s:gsub ( "(cos)%s-(%b())" , do_mathop )
s = s:gsub ( "(det)%s-(%b())" , do_mathop )
s = s:gsub ( "(exp)%s-(%b())" , do_mathop )
s = s:gsub ( "(lim)%s-(%b())" , do_mathop )
s = s:gsub ( "(sin)%s-(%b())" , do_mathop )
s = s:gsub ( "(tan)%s-(%b())" , do_mathop )
-- sqrt function
for i=1,3 do -- allow for nested sqrt expressions
s = s:gsub ( "sqrt%s-(%b())", do_sqrt )
end
-- fraction expressions
s = s:gsub ( "(%b())%s-/%s-(%b())" , do_frac_2parens )
s = s:gsub ( "([\\%w]+)%s-/%s-(%b())" , do_frac_1parens_numer )
s = s:gsub ( "(%b())%s-/%s-([\\%w]+)" , do_frac_1parens_denom )
s = s:gsub ( "([\\%w]+)%s-/%s-([\\%w]+)", "\\frac{%1}{%2}" )
-- Feel free to add more string.gsub ops as needed...
-- Return the modified string
return s
end -- end of 'prettymath' function
-- Finally, set up the helper Lua functions
function strip ( x ) -- remove first and last char of string "x"
return x:sub(2,-2)
end
function do_exp ( u )
return ( "^{" .. strip(u) .. "}" )
end
function do_gr_letter ( u )
return ( "\\"..u )
end
function do_mathop ( u , v )
return ( "\\" .. u .. v )
end
function do_integral ( u )
u = strip(u)
return ( "\\int\\! " .. u:gsub ( "^(.*),(.*)$" ,
"%1 \\,\\mathrm{d} %2" ) )
end
function do_sqrt ( u )
return ( "\\sqrt{" .. strip(u) .. "}" )
end
-- process expressions involving fractions
function do_frac_1parens_numer ( u , v )
return ( "\\frac{" .. u .. "}{" .. strip(v) .. "}" )
end
function do_frac_1parens_denom ( u , v )
return ( "\\frac{" .. strip(u) .. "}{" .. v .. "}" )
end
function do_frac_2parens ( u , v )
return ( "\\frac{" .. strip(u) .. "}{" .. strip(v) .."}" )
end
Best Answer
No Warranty nor Liability for any purpose.
produces (external frame added):
updated (Nov. 2018) for curly braces
as requested per comment:
second request for
\|
but I think it would be better to usemathtools
declarations and input syntax for this.Here, no nesting of
\|
and they must be used in pairs.Finally, (but this is becoming hacky), a trick to allow nesting
\|
one-level deep. Might be enough for use case in Banach space theory (I hear this is some 20th century old-fashioned math, that long time ago, so that might be enough for elementary human thinking pre-dating AI)(*)(*) should I explain I don't believe anything about what the highly paid software industry is throwing at us about what AI will be soon?