3
$\begingroup$

I have a simple prime counting function using the Cyclotomic function.

myPi[n_] := Sum[KroneckerDelta[Cyclotomic[m, 1], m], {m, 1, n}]  
myPi[1001] == PrimePi[1001]  

When I copy as latex I get, $$\text{myPi} n\text{:=}\sum _{m=1}^n \delta _{C_m(1),m}, $$ where I have to place $()$ around the $n$, which seems to be a bug.

However, my question: Is there an option to cause the $C$ to become the traditional $\Phi$, as below?

$$\text{myPi}(n)\text{:=}\sum _{m=1}^n \delta _{\Phi_m(1),m}.$$

$\endgroup$
4
  • $\begingroup$ How are you using the Latex code? Are you not copying it to your Latex editor to use? Then why not simply in the editor, do global search and replace? Replace C_m with \Phi_m and that should do it? $\endgroup$
    – Nasser
    Commented Oct 8, 2016 at 8:59
  • $\begingroup$ @Nasser, that's what I do. This also occurs with a few other symbols, so I was wondering if I could set an option to use a substiture character. $\endgroup$ Commented Oct 8, 2016 at 9:15
  • $\begingroup$ I do not think there is a way to do it in Mathematica itself (I mean to tell it to change how the Latex is generated), but I could be wrong. I always did the replacements in the Latex editor each time. $\endgroup$
    – Nasser
    Commented Oct 8, 2016 at 9:30
  • $\begingroup$ @Nasser, I was thinking there might be a symbol synonym list to select from. $\endgroup$ Commented Oct 8, 2016 at 9:32

3 Answers 3

5
$\begingroup$

A simple solution would be to define the function

\[CapitalPhi][m_, k_] := Cyclotomic[m, k]

Then write your comparision as

myPi[n_] := Sum[KroneckerDelta[\[CapitalPhi][m, 1], m], {m, 1, n}]
myPi[1001] == PrimePi[1001]

(* Out[505]= True *)

Copying the first line as Latex gives the string

\text{myPi}(\text{n$\_$})\text{:=}\sum _{m=1}^n \delta _{\Phi (m,1),m}

which shows up as

$$\text{myPi}(\text{n$\_$})\text{:=}\sum _{m=1}^n \delta _{\Phi (m,1),m}$$

$\endgroup$
1
  • $\begingroup$ I didn't think about puting a wrapper around it! +1 $\endgroup$ Commented Oct 8, 2016 at 11:04
5
$\begingroup$

Conversion to $\TeX$ internally uses TraditionalForm boxes. $C$ is already used there:

Cyclotomic[m, 1] // TraditionalForm

$ C_m(1) $

In definition of Cyclotomic:

?? Cyclotomic
(* ...
Cyclotomic/:MakeBoxes[Cyclotomic[BoxForm`a$_,BoxForm`b$_],TraditionalForm]/;BoxForm`sufficientVersionQ[6.1]:=
    TemplateBox[{MakeBoxes[BoxForm`a$,TraditionalForm],MakeBoxes[BoxForm`b$,TraditionalForm]},Cyclotomic]
... *)

we can see that conversion to TraditionalForm boxes use a TemplateBox with "Cyclotomic" style.

Inspection of "Cyclotomic" style:

CurrentValue[{StyleDefinitions, "Cyclotomic"}]
(* {TemplateBoxOptionsDisplayFunction ->
        (RowBox[{SubscriptBox["C", #1], "(", #2, ")"}] &),
    TemplateBoxOptionsTooltip -> Automatic} *)

reveals DisplayFunction, that is used by TemplateBox with this style, containing "C" that you'd like to change.


You can create your own StyleSheet with modified DisplayFunction:

Export[
    FileNameJoin@{$UserBaseDirectory, "SystemFiles", "FrontEnd", "StyleSheets", "MyCyclotomic.nb"},
    Notebook[{
        Cell[StyleData[StyleDefinitions -> "Default.nb"]],
        Cell[StyleData["Cyclotomic"], TemplateBoxOptions -> {
            DisplayFunction -> (RowBox[{SubscriptBox["Φ", #], "(", #2, ")"}] &),
            Tooltip -> Automatic
        }]
    }, StyleDefinitions -> "PrivateStylesheetFormatting.nb"]
]
(* ".../.Mathematica/SystemFiles/FrontEnd/StyleSheets/MyCyclotomic.nb" *)

and set it as StyleSheet of current notebook:

SetOptions[EvaluationNotebook[], StyleDefinitions -> "MyCyclotomic.nb"]

Now any conversion to $\TeX$ of Cyclotomic will give expected Φ:

Cyclotomic[m, 1] // TeXForm
(* \Phi _m(1) *)
$\endgroup$
2
  • $\begingroup$ +1, Very nice! Is this something that would carry on to child notebooks? $\endgroup$ Commented Oct 8, 2016 at 14:19
  • $\begingroup$ @FredKline Export step creates stylesheet notebook in place that is searched by Mathematica, so it should be "avalilable" for all notebooks. SetOptions[EvaluationNotebook[], ...] sets this stylesheet permanently, but only for currently used notebook (you could also do it by using menu Format > Stylesheet > MyCyclotomic). If you want to use this stylesheet, by default, in other notebooks, you could change value of DefaultStyleDefinitions option. $\endgroup$
    – jkuczm
    Commented Oct 8, 2016 at 15:40
3
$\begingroup$

Perhaps this slight workaround, or some elements of it, will be useful. First, save your expression in a variable myTradFcn

myTradFcn = TraditionalForm@Style[#, Black] &@ HoldForm[Sum[KroneckerDelta[Cyclotomic[m, 1], m], {m, 1, n}]]

Then ReplaceAll to swap the C for a φ

myNewFcn = myTradFcn /. {Cyclotomic[a_, b_] -> HoldForm[Subscript[Φ, a][b]]}

Once you've done this, you can Export it in png format (to produce the output as shown above)

tempimage = Rasterize[
  myNewFcn,
  RasterSize -> 1600, ImageSize -> {Automatic, 300}, ImageFormattingWidth -> 1600];
Export[
  "~/Desktop/image.png", 
  Framed[tempimage, FrameMargins -> 8, FrameStyle -> Directive[White]]]

or Export as "TeX"

Export[
  "~/Desktop/texformula",
    Framed[myNewFcn, FrameMargins -> 8, FrameStyle -> Directive[White]], "TeX"]

When I open the resulting texformula file in LaTeX and typeset, this last image displays with the summation indices in a compact form, but in LaTeX you can replace \sum_{m=1}^n with \sum\limits_{m=1}^n to force the indices to be above and below the summation sign.

$\endgroup$
1
  • 1
    $\begingroup$ (at)zentient Good idea to work in TraditionalForm[] variables. But instead of using the bypass Export you can simply CopyAsLatex the output of MyNewFcn. $\endgroup$ Commented Oct 8, 2016 at 12:20

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.