1
$\begingroup$

I would like to get the following equation in TeXForm

enter image description here

Here y(t), G and F are vectors and are in bold. If I do

TeXForm[HoldForm[y''[t] + G[y'[t], y[t]] == F[t]]]

in an Input Cell I get the correct TeX but not with the appropriate symbols in bold. The required equation is set up in a TradionalForm cell with the correct bold symbols. However, I don't seem to be able to export this to TeX. Is this possible or is there another work around? Possibly this answer is relevant.

$\endgroup$
2
  • $\begingroup$ How have you set up the bold symbols in TraditionalForm? $\endgroup$
    – Carl Woll
    Nov 7, 2023 at 20:46
  • $\begingroup$ In a TraditionalForm cell everything is automatically in bold. I you don' want bold then you have to un-bold the symbol. However in an input cell it is difficult to make a bold symbol. My thinking was that you could try and convert a TraditionalForm Cell to TeX. $\endgroup$
    – Hugh
    Nov 7, 2023 at 22:15

2 Answers 2

0
$\begingroup$

See TeXForm help. No Mathematica format boxes are translated, only single character symbols as italics and word symbols as \text{} boxes are used in translation.

This yields a possibility to modify an expressions TeXForm, as a string, e.g. by

 raw = "$$" <> ToString[TeXForm[y''[x] == Sin[x]]] <> "$$" 

  bold = StringReplace[raw, "y" -> "\\mathbf{y}"] 

$$\mathbf{y}''(x)=\sin (x)$$

     Import[ StringToStream[bold], "LaTeX" ]  




Notebook[{Cell[TextData[{}], "Text"], 
   Cell[BoxData[FormBox[RowBox[{SuperscriptBox[StyleBox["y",
   FontSlant -> "Bold"],"\[Prime]\[Prime]"], 
   RowBox[{"(", StyleBox["x", "TI"], ")"}],"\[LongEqual]", "sin", 
   RowBox[{"(", StyleBox["x", "TI"], ")"}]}], TraditionalForm]],
   "NumberedEquation"]}, StyleDefinitions -> "Default.nb"]
$\endgroup$
0
$\begingroup$

You can use a replacement rule for the example you posted. For each of these rules, the lhs is a Mathematica expression and the rhs is the styled string you want to see in the TeX, representing that expression.

TeXForm[HoldForm[y''[t] + G[y'[t], y[t]] == F[t]]]

(* y''(t)+G\left(y'(t),y(t)\right)=F(t) *)

This is basically just a string. Now just replace G,y,F with Style[_,Bold]:

%2 /. {G -> Style["G", Bold], y -> Style["y", Bold], 
  F -> Style["F", Bold]}

(It doesn't render well in the browser so I'll post a screenshot.) enter image description here

If you also want to use bold type for the "primes" on the derivatives, you need to write a pattern which matches the derivative operator in the code. In this case, the nth derivative is Derivative[n][y][t]. Since you're mapping to a string, each 'n' must be written separately. To get the arguments in normal weight, use a second "Text" style box for each "[t]".

%2 /. {G -> Style["G", Bold], y -> Style["y", Bold], 
  F -> Style["F", Bold], 
  Derivative[1][y][t] :> Style["y'", Bold] Style["[t]", "Text"], 
  Derivative[2][y][t] :> Style["y''", Bold] Style["[t]", "Text"]}

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.