# How can I convert Sin[2 x] to \sin 2x and put result of Mathematica in a list in LaTeX like this?

I tried

ReplaceAll[
Table[{Sin[2  x] == Sqrt[i]/2,
Expand[Reduce[Sin[2    x] == Sqrt[i]/2, x, Reals]]}, {i, 0, 4}],
C[1] -> k]


and got

I copy the result of Mathematica to LaTeX by hand

\documentclass[12pt,a4paper]{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{enumitem}
$$\begin{document} Solve the equations: \begin{enumerate}[label=\arabic*)] \item \sin 2x = 0 \hfill Answer. k\in \mathbb{Z}\land \left(x=\pi k\lor x=\pi k+\dfrac{\pi }{2}\right). \item \sin 2 x=\dfrac{1}{2}. \hfill k\in \mathbb{Z}\land \left(x=\pi k+\dfrac{\pi }{12}\lor x=\pi k+\dfrac{5 \pi }{12}\right). \item \sin 2 x=\dfrac{1}{\sqrt{2}}. \hfill Answer. k\in \mathbb{Z}\land \left(x=\pi k+\dfrac{\pi }{8}\lor x=\pi k+\dfrac{3 \pi }{8}\right). \item \sin 2 x=\dfrac{\sqrt{3}}{2}. \hfill Answer. k\in \mathbb{Z}\land \left(x=\pi k+\dfrac{\pi }{6}\lor x=\pi k+\dfrac{\pi }{3}\right). \item \sin 2 x=1 . \hfill Answer. k\in \mathbb{Z}\land x=\pi k+\dfrac{\pi }{4}. \end{enumerate} \end{document}$$


How can I convert Sin[2x] from Mathematica to \sin 2x in LaTeX and put the result of Mathematica in a list?

• I copy the result of Mathematica to LaTeX by hand how could this be possible? did you do TeXForm first? How can I convert Sin[2x] from Mathematica to \sin 2x in LaTeX If you do TeXForm[Sin[2 x]] then you will get what you want. I am not sure still what is it you are asking here. Commented May 17 at 8:37
• TeXForm[Sin[2 x]] gives \sin (2 x). Can I get \sin 2x? Commented May 17 at 8:41
• I copy the result of Mathematica to LaTeX by hand. I used copy as LaTeX of Mathematica. Commented May 17 at 8:42
• Can I get \sin 2x I do not think you can change this. Mathematica groups $2x$ as $(2x)$ as it is an argument to $\sin$. I think this is better myself. What if you had Sin[x y]? do you want this to show as $\sin xy$ ? This is ambiguous. Someone can read this as $\sin(x) y$ instead of $\sin(xy)$. Explicit is always better than implicit. (except in some finite difference schemes) Commented May 17 at 8:47
• @Nasser $\sin xy$ and $\sin(xy)$ have been standard for centuries (well, $> 1$, at least). Commented May 17 at 14:46

Using the approach in TeXForm and large brackets (\Biggl[ etc):

$$funcsPat = "sin" | "cos" | "tan" | "csc" | "sec" | "cot" | "log"; mytexrules = { RowBox[{f : funcsPat, "(", arg_, ")"}] /; ! MatchQ[arg (* exceptions to no parentheses *) , RowBox[{_, "+" | "-", __}] | (* Plus *) (_ /; LeafCount[arg] > 20) | (* complicated arg *) (_ /; Count[arg, _FractionBox, Infinity] > 1) (* complicated arg *) ] :> ConvertTeXBoxesToTeX[RowBox[{f, arg}]] }; TeXForm[1 + x](*initializes SystemConvertTeXFormDump$$GreekWords*)

If[MatchQ[oldGreekWords, _List],(* reset $$GreekWords, if necessary *) SystemConvertTeXFormDump$$GreekWords = oldGreekWords];

If[! MatchQ[oldGreekWords, _List],
oldGreekWords = SystemConvertTeXFormDump$GreekWords]; If[MatchQ[oldGreekWords, _List], SystemConvertTeXFormDump$GreekWords = Join[mytexrules, oldGreekWords],
"Warning: SystemConvertTeXFormDump\$GreekWords not initialized"];


Examples

As Nasser intimates, parsing traditional parenthesization, especially for functions and multiplication, is not easy and is different from the standard grammars found in computer languages. The language of math is probably evolving toward parenthesizing function-argument combination, probably because of the influence of calculators in school. At least I notice more mathematicians and students always using parentheses in lower-level undergraduate courses. (Nonetheless, people are still adhering to $$\sin^2 x$$ instead using the more straightforward $$(\sin x)^2$$.) The code below tries to adhere to the older tradition of omitting parentheses when unnecessary. "Unnecessary" always has involved a judgment call and does not follow strict rules. Of course, the code above implements a strict rule. One general rule is that arguments that are sums or differences should be enclosed in parentheses. Products need not be parenthesized, but it may be helpful to do so if the argument is too complicated (another judgment call).

Sin[x] // TeXForm
(*  \sin x  *)

Sin[x  y] // TeXForm
(*  \sin x y  *)

1 + Sin[(x + y)/2] // HoldForm // TeXForm
(*  1+\sin \frac{x+y}{2}  *)

Sin[x^2 y (x + y)/2] // TeXForm
(*  \sin\left(\frac{1}{2} x^2 y (x+y)\right)  *)

Sin[(x/2 + y)/2] // TeXForm
(*  \sin\left(\frac{1}{2} \left(\frac{x}{2}+y\right)\right)  *)


When a constant or variable is added to a function, I prefer to put the term in front of the function. Mathematica prefers to sort the terms into the standard ordering in TraditionalForm. The use of HoldForm above is a way to hold the ordering as typed.

Use TeXForm

   TeXForm[TableForm[
ReplaceAll[
Table[{Sin[2 x] == Sqrt[i]/2,
Expand[Reduce[Sin[2 x] == Sqrt[i]/2, x, Reals]]}, {i, 0, 4}],
C[1] -> k]]]


and cut an paste the output text by Ctrl+C

$$\begin{array}{cc} \sin (2 x)=0 & k\in \mathbb{Z}\land \left(x=\pi k\lor x=\pi k+\frac{\pi }{2}\right) \\ \sin (2 x)=\frac{1}{2} & k\in \mathbb{Z}\land \left(x=\pi k+\frac{\pi }{12}\lor x=\pi k+\frac{5 \pi }{12}\right) \\ \sin (2 x)=\frac{1}{\sqrt{2}} & k\in \mathbb{Z}\land \left(x=\pi k+\frac{\pi }{8}\lor x=\pi k+\frac{3 \pi }{8}\right) \\ \sin (2 x)=\frac{\sqrt{3}}{2} & k\in \mathbb{Z}\land \left(x=\pi k+\frac{\pi }{6}\lor x=\pi k+\frac{\pi }{3}\right) \\ \sin (2 x)=1 & k\in \mathbb{Z}\land x=\pi k+\frac{\pi }{4} \\ \end{array}$$

• Your result is sin(2x). How can I get sin 2x`? Commented May 17 at 8:40
• Edit the TeXForm output by hand. Generally, TeXForm generates a raw typesetting, that is not the optimal exposition wrt to grouping and order of orderless sums and products. Especially products of rationals need an edit postprocessing. Commented May 17 at 14:13