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:

lualatexand use thefontspecpackage with an OpenType font? That increases the possibilities tremendously. – rallg Apr 03 '23 at 17:12