4
$\begingroup$

I am using the MaTeX package so that symbols can have a widehat over them, e.g., $\widehat{X}$. In particular, here is the code I am using:

Needs["MaTeX`"];

`MaTeX["\\widehat{X}"]`

Is there a way to ensure that this MaTeX symbol's typesetting is equivalent to the following Mathematica text:

Style[OverHat["X"], Black, FontSize -> 20,FontFamily->"Arial"]

That is, can I keep the MaTeX overhat but change the text font so that it is Arial, black, size 20 font?

$\endgroup$
3
  • 1
    $\begingroup$ MaTeX evaluates LaTeX code. You need to change the font in LaTeX. This is discussed in the "Typesetting with MaTeX" tutorial, included in the MaTeX docs. In short: You can't use arbitrary fonts for math. The font needs to have proper math support. There is a limited selection of these. $\endgroup$ Commented Apr 2 at 16:28
  • 2
    $\begingroup$ I have seen many PhD students lose weeks and weeks of their precious time on formatting issues. Some want to have an identical font for the article's body and figures' captions. Some want to make fonts in presentations/posters identical to the font in figures. My advice is not to focus overly on these issues. $\endgroup$ Commented Apr 3 at 6:44
  • 1
    $\begingroup$ @yarchik Thank you for this advice; I am definitely one of those students (technically post-doc now)! $\endgroup$ Commented Apr 3 at 21:18

1 Answer 1

5
$\begingroup$

You mentioned in your other comment you did this. Well, here is my attempt.

Just to be clear. In Mathematica Style[OverHat["X"],... is done in text mode. While MaTeX works in Math mode. So you can not expect same output as is. To use MaTeX in textmode, need to use \text command in Latex which allows one to insert text in math mode.

To use Matex to generate the same output:

To set font to Arial, need to use lualatex as not possible with pdflatex. So need to tell MaTeX to use lualatex

Needs["MaTeX`"]
ConfigureMaTeX["pdfLaTeX"->"C:\\Users\\Owner\\AppData\\Local\\Programs\\MiKTeX\\miktex\\bin\\x64\\lualatex.exe"];
SetOptions[MaTeX,"Preamble"->{"\\usepackage{fontspec}\\setmainfont{Arial}\\usepackage{amsmath}"}];

And now, to use 20pt in Latex also

MaTeX["\\text{\\fontsize{20pt}{16pt}\\selectfont \\^{X}}"]

Same as Mathematica. Screen shot (but the hat I used is a little bit different size).

enter image description here

All under windows 10.

MaTeX works in math mode. So had to use \text in the above. Can not use text directly inside MaTeX call.

If you want wider hat in textmode, you can try this

Needs["MaTeX`"]
ConfigureMaTeX["pdfLaTeX"->"C:\\Users\\Owner\\AppData\\Local\\Programs\\MiKTeX\\miktex\\bin\\x64\\lualatex.exe"];
SetOptions[MaTeX,"Preamble"->{"\\usepackage{fontspec}\\setmainfont{Arial}\\usepackage{amsmath}\\catcode`@=11
\\def\\twidehat#1{$\\m@th\\widehat{\\hbox{#1}}$}
\\catcode`@=12"}];

And now

MaTeX["{\\text{\\fontsize{20pt}{16pt}\\selectfont \\twidehat{X}}}"]

enter image description here

Reference:

https://tex.stackexchange.com/questions/647544/widehat-in-text-mode-in-plain-xetex

$\endgroup$
2
  • $\begingroup$ Is Magnification->1.6 equivalent to a font size of 20 in Mathematica? $\endgroup$ Commented Apr 3 at 4:55
  • $\begingroup$ @user107421 updated to use exact same font size 20 pt in Latex $\endgroup$ Commented Apr 3 at 5:11

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.