1

I want to draw some fun integral signs, namely a "happy" Integral

Happy Integral

but im having Problems doing it in a way that respects textsize and display-styles. Im using the approach of egregs Answer here.

In my "integrale.tex" i have

\makeatletter
\newlength{\mybox}
\DeclareRobustCommand\inttest{\vphantom{\int}\mathpalette\aw@qc\relax}
\newcommand{\aw@qc}[2]{%
    \sbox\mybox{$#1 \int$}%
    \dimen1 = \dimexpr\wd\mybox\relax %"Width" - Width of the bounding box
    \dimen2 = \dimexpr\ht\mybox\relax %"Height" - distance between baseline and upper box side
    \dimen3 = \dimexpr\dp\mybox\relax %"Depth" - Abstand zwischen baseline lower box side
    \dimen4 = 0.5\dimexpr\ht\z@-\dp\z@\relax %y_coordinate of center of bounding box (Average of Height and Depth)
    \fbox{$#1 \int$}\put(-\dimen1,\dimen4){\relativearms}
}
\makeatother

\newcommand{\test}{\relativearms \text{\ \ \ } \text{\ \ \ } \inttest abc}
\newcommand{\relativearms}{\put(0em,0em){\line(-1,2.2){0.15em}}\put(0em,0em){\line(1,2.2){0.15em}}}

and for testing the results im using "testing.tex"

\documentclass[a4paper,12pt]{article}
\usepackage{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{amsmath,amssymb,amsfonts,amsthm}
\usepackage{pict2e} % To get around errorof \line :"LaTeX Warning: \oval, \circle, or \line size unavailable"
\usepackage{fbox}
\input{integrale.tex}
\begin{document}
%Testing

\begin{footnotesize}
    Footnotesize:
    $\textstyle \test$
    $\displaystyle \test$
    $ \scriptstyle \test$
    $ \scriptscriptstyle \test$
\end{footnotesize}\\ \ \\

\begin{small}
    small:
    $\textstyle \test$
    $\displaystyle \test$
    $ \scriptstyle \test$
    $ \scriptscriptstyle \test$
\end{small}\\ \ \\

\begin{normalsize}
    normalsize:
    $\textstyle \test$
    $\displaystyle \test$
    $ \scriptstyle \test$
    $ \scriptscriptstyle \test$
\end{normalsize}\\ \ \\

\begin{large}
    large:
    $\textstyle \test$
    $\displaystyle \test$
    $ \scriptstyle \test$
    $ \scriptscriptstyle \test$
\end{large}\\ \ \\

\begin{Large}
    Large:
    $\textstyle \test$
    $\displaystyle \test$
    $ \scriptstyle \test$
    $ \scriptscriptstyle \test$
\end{Large}\\ \ \\

\end{document}

This produces the output Output

  1. (Most important):
    As you can see, only in displaystyle my arms aren't beginning in the middle of the box and i can't figure out why and how to fix this.
  2. The arms arent scaling in proportion to the integral sign. The integrals of the "large" row have arms that are too long to be proportional. How come the integral signs dont seem to get larger with larger text size? (With the large versions the arms are touching the head.)
3
  • 1
    Welcome to TeX.SE!
    – Mensch
    Apr 3, 2023 at 16:29
  • Any possibility that you could switch compiler to lualatex and use the fontspec package with an OpenType font? That increases the possibilities tremendously.
    – user287367
    Apr 3, 2023 at 17:12
  • I believe i managed to install lualatex on my windows and include the fontspec package.Do i need to download OpenType fonts?I don't see how lualatex will be helping me atm
    – Rubids
    Apr 3, 2023 at 20:06

1 Answer 1

0

The following solution is probably only that long because i am a total tikz noob. Dont shy away because of length. The critical part of the solution is this:

\newcommand{\happyint}{\mathpalette\happyint@\relax}
\newcommand{\happyint@}[2]{
    %#1 is mathstyle e.g \displaystyle or \textstyle #2 not used but needed because of mathpalette
    \tikz[baseline=(box.base), inner sep=0pt,outer sep=0pt]{
        \node[anchor=center] (box) at (0,0) {$#1\int$};
        \computeCoords{box}
        %\drawbox@
        \happyarms@{#1}
    }
}

Also see the output in the bottom of this post.

I eventually figured a way out. Essentially nothing was wrong with my approach, i still don't know why it doesnt work. Now i just use tikz to draw the arms. I still need to adjust what i am drawing when in displaymode, but that is because the aspect ratio of the integral essentially changes so are too long and too far right without adjustment (but now it is always the same adjustment in each math mode)

Essentially i am using tikz to get a box around a normal integral (uncomment \drawbox to see this box) calculate some vectors and draw my arms dependant on the boxes coordinates.

I also found a way to always get exactly the same bounding box as a normal integral sign would even if you decide to draw outside of the tikz box. See the comment at the end of the integrale_min.tex (it adds huge compiletime for some reason and for this example it is not needed):

\usepackage{mathtools} %for \mathmakebox if needed
\usepackage{tikz}
\makeatletter
\usetikzlibrary{calc}


\newcounter{inDispStyle}
\newcommand{\computeCoords}[1]{
    \coordinate (centerToNorth) at ($ (#1.north) - (#1.center) $);
    \coordinate (centerToEast) at ($ (#1.east) - (#1.center) $);
    \coordinate (centerToSouth) at ($ (#1.south) - (#1.center) $);
    \coordinate (centerToWest) at ($ (#1.west) - (#1.center) $);
    \coordinate (center) at (#1.center);
    \coordinate (north) at (#1.north);
    \coordinate (east) at (#1.east);
    \coordinate (south) at (#1.south);
    \coordinate (west) at (#1.west);
    \coordinate (northwest) at (#1.north west);
    \coordinate (northeast) at (#1.north east);
    \coordinate (southeast) at (#1.south east);
    \coordinate (southwest) at (#1.south west);

}

\newcommand{\drawbox@}{
    \draw (northwest) -- (northeast) ;
    \draw (northeast) -- (southeast) ;
    \draw (southeast) -- (southwest) ;
    \draw (southwest) -- (northwest) ;
}

\newcommand{\happyarms@}[1]{
    %#1 should be mathstyle, passed through from mathpalette
    \ifx#1\displaystyle
        \setcounter{inDispStyle}{1}
    \else
        \setcounter{inDispStyle}{0}
    \fi
    %
    \coordinate (rightArmBegin) at ($(center)+0.1*(centerToNorth)+0.1*\theinDispStyle*(centerToEast)$);
    \coordinate (leftArmBegin) at ($(center)+0.1*(centerToNorth)+0.1*\theinDispStyle*(centerToEast)$);
    \coordinate (rightArmEndFull) at ($(centerToEast)+0.55*(centerToNorth)$);
    \coordinate (leftArmEndFull) at ($(centerToWest)+0.85*(centerToNorth)$);
    \coordinate (rightArmEnd) at ($(rightArmBegin)!0.75!(rightArmEndFull)$);
    \coordinate (leftArmEnd) at ($(leftArmBegin)!0.6!(leftArmEndFull)$);
    \draw (rightArmBegin) -- (rightArmEnd);
    \draw (leftArmBegin) -- (leftArmEnd);
}

\newcommand{\happyint}{\mathpalette\happyint@\relax}
\newcommand{\happyint@}[2]{
    %#1 is mathstyle e.g \displaystyle or \textstyle #2 not used but needed because of mathpalette
    \tikz[baseline=(box.base), inner sep=0pt,outer sep=0pt]{
        \node[anchor=center] (box) at (0,0) {$#1\int$};
        \computeCoords{box}
        %\drawbox@
        \happyarms@{#1}
    }
}
%If you want the result to have exactly the same bounding box as a regular integral regardless of what you decide to draw with tikz you can use: 
%\newcommand{\happyintvariant}{\smash{\mathmakebox[0pt][l]{\mathpalette\happyint@\relax}}\phantom{\int}}
\makeatother
\newcommand{\test}{\happyint}
\newcommand{\vergleich}{\int}

The testing file draws the happy integral next to the normal integral in each mathmode in each size. fboxes are added so we can see that the bounding box in this case is the same as normal (even without using the commented line).

You can change the text size in \documentclass[a4paper,12pt]{article} to whatever you fancy.

My testing.tex contains:

\documentclass[a4paper,12pt]{article}
\input{integrale.tex}
\begin{document}
%Testing
\makeatletter
\begin{footnotesize}
    Footnotesize:
    \fbox{\m@th $\textstyle \test $} \fbox{\m@th $\textstyle \vergleich $}
    \fbox{\m@th $\displaystyle \test $} \fbox{\m@th $\displaystyle \vergleich $}
    \fbox{\m@th $\scriptstyle \test $} \fbox{\m@th $\scriptstyle \vergleich $}
    \fbox{\m@th $\scriptscriptstyle \test $} \fbox{\m@th $\scriptscriptstyle \vergleich $}
\end{footnotesize}\\ \ \\

\begin{small}
    small:
    \fbox{\m@th $\textstyle \test $} \fbox{\m@th $\textstyle \vergleich $}
    \fbox{\m@th $\displaystyle \test $} \fbox{\m@th $\displaystyle \vergleich $}
    \fbox{\m@th $\scriptstyle \test $} \fbox{\m@th $\scriptstyle \vergleich $}
    \fbox{\m@th $\scriptscriptstyle \test $} \fbox{\m@th $\scriptscriptstyle \vergleich $}
\end{small}\\ \ \\

\begin{normalsize}
    normalsize:
    \fbox{\m@th $\textstyle \test $} \fbox{\m@th $\textstyle \vergleich $}
    \fbox{\m@th $\displaystyle \test $} \fbox{\m@th $\displaystyle \vergleich $}
    \fbox{\m@th $\scriptstyle \test $} \fbox{\m@th $\scriptstyle \vergleich $}
    \fbox{\m@th $\scriptscriptstyle \test $} \fbox{\m@th $\scriptscriptstyle \vergleich $}
\end{normalsize}\\ \ \\

\begin{large}
    large:
    \fbox{\m@th $\textstyle \test $} \fbox{\m@th $\textstyle \vergleich $}
    \fbox{\m@th $\displaystyle \test $} \fbox{\m@th $\displaystyle \vergleich $}
    \fbox{\m@th $\scriptstyle \test $} \fbox{\m@th $\scriptstyle \vergleich $}
    \fbox{\m@th $\scriptscriptstyle \test $} \fbox{\m@th $\scriptscriptstyle \vergleich $}
\end{large}\\ \ \\

\begin{Large}
    Large:
    \fbox{\m@th $\textstyle \test $} \fbox{\m@th $\textstyle \vergleich $}
    \fbox{\m@th $\displaystyle \test $} \fbox{\m@th $\displaystyle \vergleich $}
    \fbox{\m@th $\scriptstyle \test $} \fbox{\m@th $\scriptstyle \vergleich $}
    \fbox{\m@th $\scriptscriptstyle \test $} \fbox{\m@th $\scriptscriptstyle \vergleich $}
\end{Large}\\ \ \\
\makeatother
\end{document}

This produces the output: Output

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .