6

I wonder if there could be a tricky automated way to detect fractions within "parentheses, brackets, braces" to adjust their heights to the maximum height of the candidates. See picture below and highlighted in yellow.

enter image description here

The minimal example is given by:

\documentclass{article}
\usepackage{amsmath,amssymb}
\begin{document}
\begin{align*}
I_x&=\int y^2\,\underbrace{\text{d}A}_{=\text{d}x\text{d}y}=4\left(\int    \limits_{x=0}^{\frac{B}{2}-\frac{b}{2}}\int \limits_{y=0}^{\frac{H}{2}}y^2\,\text{d}y\text{d}x+\int\limits_{x=\frac{B}{2}-\frac{b}{2}}^{\frac{B}{2}}\int \limits_{y=\frac{h}{2}}^{\frac{H}{2}}y^2\,\text{d}y\text{d}x\right)\\
&=4\left(\left[x\right]_{x=0}^{\frac{B}{2}-\frac{b}{2}}\cdot \left[\frac{1}{3}y^3\right]_{y=0}^{\frac{H}{2}}+\left[x\right]_{x= \frac{B}{2}-\frac{b}{2}}^{\frac{B}{2}}\cdot \left[\frac{1}{3}y^3\right]_{y=\frac{h}{2}}^{\frac{H}{2}}\right)\\
&=\frac{BH^3-bh^3}{12}
\end{align*}
\end{document}

Any hints appreciated. As told above - the target is to detect the fractions and then adjust the height to all other parentheses, brackets, braces alike.

The way I did looks quite ugly to my sense of good typing ...

Hope I was precise enough!

  • 1
    If you want all braces/parens to be of a fixed size, use \big, \bigg, \Big, or \Bigg instead of \left...\right. – Steven B. Segletes Apr 14 '18 at 20:18
  • Yes, I know - I was asking about how to detect the fractions and therefore automatically get the correct height for the other candidates and if no fractions inside - take the normal height as given by \left...\right ... I thought there could be a solution with LaTeX3 and xparse to make such detection ... –  Apr 14 '18 at 20:27
  • Well considering how easy it is for your editor to change all at once, the \bigs to \Biggs, it seems trivial to just do it with the editor, rather than writing code to detect and remedy it. – Steven B. Segletes Apr 14 '18 at 20:32
  • @JürgenG In mathematical mode it is deprecable to use \text{d}; you should use \mathrm{...} or for bold simbol \mathbf. – Sebastiano Apr 14 '18 at 20:36
  • Definitely you are right, that is not my major problem. Considering the solution of Sebastiano - of course this does the job. However does this look better? With detection of fractions I was thinking of finding fractions that only contain NUMBERS to then then use \tfrac{}{} compared to functions that contain \frac{x^2}{x^2-1} or so which seem to be displystyle ... I seem to not have been precise enough, sorry about that. Of course I can do that manually integral by integral, but there are hundreds of them which I like to get under "typesetting fine" control. –  Apr 14 '18 at 20:44
  • 1
    @JürgenG, have you considered accepting an answer? – PatrickT Jan 26 '19 at 08:54

2 Answers2

5

I prefer for brackets and parentheses this version. Each of us has a style to write mathematical formulas. The style which suits the most to you would be this.

enter image description here

\documentclass{article}
\usepackage{amsmath,amssymb,mathtools}
\begin{document}
\begin{align*}
I_x&=\int y^2\underbrace{\mathrm{d}A}_{=\mathrm{d}x\mathrm{d}y}=4\left(\int \limits_{x=0}^{\frac{B}{2}-\frac{b}{2}}\int \limits_{y=0}^{\frac{H}{2}}y^2\mathrm{d}y\mathrm{d}x+\int\limits_{x=\frac{B}{2}-\frac{b}{2}}^{\frac{B}{2}}\int \limits_{y=\frac{h}{2}}^{\frac{H}{2}}y^2\mathrm{d}y\mathrm{d}x\right)\\
&=4\left(\bigg[x\bigg]_{x=0}^{\frac{B}{2}-\frac{b}{2}}\cdot \left[\frac{1}{3}y^3\right]_{y=0}^{\frac{H}{2}}+\bigg[x\bigg]_{x= \frac{B}{2}-\frac{b}{2}}^{\frac{B}{2}}\cdot \left[\frac{1}{3}y^3\right]_{y=\frac{h}{2}}^{\frac{H}{2}}\right)\\
&=\frac{BH^3-bh^3}{12}
\end{align*}
\end{document}
Sebastiano
  • 54,118
  • 1
    You should use \biggl for left and \biggr for right, to make sure spacing gets properly adjusted. – Steven B. Segletes Apr 14 '18 at 20:30
  • Kind Steven yes of course. Before I have seen, quickly, this link: https://it.sharelatex.com/learn/Brackets_and_Parentheses. Now I have seen https://tex.stackexchange.com/questions/19480/why-use-the-control-sequences-bigl-biggl-bigr-or-biggr-as-i-can-always-us. Thanks a lot for your suggestions. – Sebastiano Apr 14 '18 at 20:34
  • @JürgenG We are here to help us all. At least that's the spirit that hovers in me for this site. If you like my answer you can check V green. – Sebastiano Apr 14 '18 at 20:55
  • @JürgenG If you like my answer or of another user you can see this link: https://tex.meta.stackexchange.com/questions/1852/how-do-you-accept-an-answer. – Sebastiano Apr 14 '18 at 21:02
4

enter image description here

\documentclass{article}
\usepackage{amsmath,amssymb}
\let\zzfrac\frac
\def\frac#1#2{\afterassignment\zzztest\count0=0#1#2\relax{#1}{#2}}
\def\zzztest#1\relax{%
\if\relax\detokenize{#1}\relax
  \expandafter\tfrac
\else
  \expandafter\zzfrac
\fi}

\begin{document}
\begin{align*}
I_x&=\int y^2\,\underbrace{\mathrm{d}A}_{=\mathrm{d}x\mathrm{d}y}=4\left(\int    \limits_{x=0}^{\frac{B}{2}-\frac{b}{2}}\int \limits_{y=0}^{\frac{H}{2}}y^2\,\mathrm{d}y\mathrm{d}x+\int\limits_{x=\frac{B}{2}-\frac{b}{2}}^{\frac{B}{2}}\int \limits_{y=\frac{h}{2}}^{\frac{H}{2}}y^2\,\mathrm{d}y\mathrm{d}x\right)\\
&=4\left(\left[x\right]_{x=0}^{\frac{B}{2}-\frac{b}{2}}\cdot \left[\frac{1}{3}y^3\right]_{y=0}^{\frac{H}{2}}+\left[x\right]_{x= \frac{B}{2}-\frac{b}{2}}^{\frac{B}{2}}\cdot \left[\frac{1}{3}y^3\right]_{y=\frac{h}{2}}^{\frac{H}{2}}\right)\\
&=\frac{BH^3-bh^3}{12}
\end{align*}
\end{document}

This switches between \frac and \tfrac which means if you use \frac in a subscript it might do the wrong thing and use \tfrac it could be made smarter but to be honest. I wouldn't it gets more fragile and it is more robust just to use \tfrac{1}{3} in the original source of you want a third.

David Carlisle
  • 757,742
  • Egregious David. My philosophy is always to recognize and appreciate the different forms of writing in mathematical mode, especially for users who are very good as you. I told the user that each of us has a way of writing any mathematical document in relation to our tastes. +1 – Sebastiano Apr 14 '18 at 21:17
  • David, this comes along much closer to what I want!!! Thank you very much for that approach!!! –  Apr 14 '18 at 21:17