Message Boards Message Boards

0
|
2726 Views
|
5 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Self-introduced integral sign being multiplied to the numerator in Latex?

Posted 2 years ago

Recently I have been doing a lot of double and triple integrals. To my disappointment, Mathematica does not have built-in integral signs for those advanced or special integrals. Fortunately, I have found out a way to introduce those integral signs from Unicode. In Mathematica, it can be input by typing the "\:unicode number "of the integral sign.

But a new problem emerged after the introduction: when converting expressions containing my self-introduced integral signs into Latex code, Mathematica will multiply the integral sign into the numerator as long as the integrand is a fractional function.

For example, I have this expression input in my note book:

\!\(\*UnderscriptBox[
StyleBox["∬",
FontSize->24], \(1 <= 
\*SuperscriptBox[\(x\), \(2\)] + 
\*SuperscriptBox[\(y\), \(2\)] <= 4\)]\) Sin[\[Pi] Sqrt[
   x^2 + y^2]]/Sqrt[x^2 + y^2] \[DifferentialD]x \[DifferentialD]y

which looks like :

enter image description here

However, the latex code Mathematica made for this expression is:

$$ \frac{\iint\limits_{1\leq x^2+y^2\leq 4}\sin \left(\pi \sqrt{x^2+y^2}\right)\mathrm{d}x\mathrm{d}y}{\sqrt{x^2+y^2}} $$

where apparently Mathematica regards my self-introduced integral sign as an ordinary term which can be multiplied into the numerator. But unfortunately, it can't. By doing so the meaning and value of the expression has totally changed from the correct one.

Moreover, I have noticed that, for built-in integral signs, Mathematica will interpret the integral expression properly and will not multiply those integral signs into the numerator, which shows there must be some way to pull it off.

I already know that to convert an expression into its TexForm, Mathematica will work on its Box representation of its traditional form. As a result, I was wondering, how I can prevent my self-introduced integral sign being multiplied into the numerator when converting it into Latex code, or more specifically, preventing so when the expression's Box representation of its traditional form is being made by Mathematica.

POSTED BY: Albert Lew
5 Replies

No, not out of the box. You have to replace \unicode{222c} with {\int\!\!\int}:

StringReplace[expr // TeXForm // ToString, 
 "\\unicode{222c}" -> "{\\int\\!\\!\\int}"]
POSTED BY: Gianluca Gorni

Gather the whole integrand into a RowBox:

expr = With[{f = Sin[Pi Sqrt[x^2 + y^2]]/Sqrt[x^2 + y^2], 
   reg = (1 <= x^2 + y^2 <= 4)}, 
  DisplayForm@
   InterpretationBox[
    RowBox[{UnderscriptBox[StyleBox["∬", FontSize -> 24], reg], 
      RowBox[{f, RowBox[{"\[DifferentialD]", x}], 
        RowBox[{"\[DifferentialD]", y}]}]}],
    Integrate[f, Element[{x, y}, ImplicitRegion[reg, {x, y}]]]]]
expr // TeXForm
POSTED BY: Gianluca Gorni

I tried putting your LATEX in here or here, doesn't work?

POSTED BY: Mariusz Iwaniuk
Posted 2 years ago

Thanks, Gianluca, for your insight. Your code works since I had defined the latex string for those special self-introduced integral signs in my notebook before I posted the question here. But the thing is: I do not want to rearrange the boxes by hand and by sight each time I need to do this kind of conversion. Because there can be a ton of integrals of this kind in one notebook of mine. What I need is a way to automate the process, like a function associated with MakeBoxes[] so that every time I do the conversion, Mathematica can recognize it is an integral sign and can not be multiplied into the numerator automatically.

If you have any idea on the automation of the process, I am all ears.

POSTED BY: Updating Name

You can use replacement rules. The rule depends on what sorts of integrals you have and the way you write them. Suppose that you write the integration region with the syntax Element[{x,y},ImplicitRegion[inequalitites,{x,y}]]. Then you can do this way:

replacementRule = 
  Integrate[f_, Element[{x_, y_}, ImplicitRegion[reg_, {x_, y_}]]] :> 
   DisplayForm@
    InterpretationBox[
     RowBox[{UnderscriptBox[StyleBox["∬", FontSize -> 24], reg], 
       RowBox[{f, RowBox[{"\[DifferentialD]", x}], 
         RowBox[{"\[DifferentialD]", y}]}]}], 
     Integrate[f, Element[{x, y}, ImplicitRegion[reg, {x, y}]]]];
mySampleDoubleIntegral = 
  Integrate[Sin[\[Pi] Sqrt[x^2 + y^2]]/Sqrt[x^2 + y^2], 
   Element[{x, y}, ImplicitRegion[(1 <= x^2 + y^2 <= 4), {x, y}]]];
mySampleDoubleIntegral /. replacementRule

The same integral can be written with other styles, for example with Boole, which may require different rules. You may also want to make rules for Inactive[Integrate].

It is hard to know what you have in mind form a single example.

POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract