Equation size similar to text size
Writing up your own class notes is a perfect situation for using TikZ. I take a rather different approach from you, but you already have several answers following your lead. I just want to illustrate a different approach to this.
\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{arrows.meta}
\newcommand\tikzmark[1]{\tikz[remember picture,overlay]\node (#1) {};}
\newenvironment{mynote}[1][]
{\begin{tikzpicture}[remember picture,overlay,#1]}
{\end{tikzpicture}}
\begin{document}
I am doing some calculations here.
\[
\int_SB\cos\alpha\hspace*{1mm}dS \tikzmark{AL}=\tikzmark{AR} B\tikzmark{BL}\cos\alpha\tikzmark{BR}\int_SdS
\]
\begin{mynote}
\path ($(AL.north)!0.5!(AR.north)$)
node (startA) {} -- ++(35:1in)
node[anchor=west,
draw,
rounded corners]
(noteA)
{\footnotesize something happens with $\cos\alpha$};
\path ($(BL.south)!0.5!(BR.south)$)
node (startB) {} -- ++(180+35:1in)
node[anchor=east,
draw,
rounded corners]
(noteB)
{\footnotesize $\cos\alpha$ is a constant};
\draw[arrows=-Stealth]
(noteA) to[out=180,in=60]
(startA);
\draw[arrows=-Stealth]
(noteB) to[out=0,in=180+60]
(startB);
\end{mynote}
\end{document}
Improvement of the above environment.
If text follows the above approach. There will be a potential class with the tikz picture. The following improvement to the environment minimizes this effect:
\newlength\mynotebottom
\newlength\myfirstlineheight
\newenvironment{mynote}[2][]
{%% #1 -- further keys to pass to the TikZ environment
%% #2 -- the first line of text to follow the environment -- used to determine
%% how much of an offeset is needed before starting with the text after
%% this tikzpicture is completed.
\settoheight\myfirstlineheight{#2}%%
%% we're not using overlays here since we'll lose all bounding box information
%% and we need that to determine where the bottom of the picture is. To create
%% the effect of an overlay, I later *reset* the bounding box.
\begin{tikzpicture}[remember picture,#1]
%% this node is originally kind of (not quite) placed where the first text
%% would have appeared.
\node[inner sep=0pt,anchor=west] (mynote/top/tmp) {\phantom{#2}};
\pgfresetboundingbox
\node[inner sep=0pt] (mynote/top) at ($(mynote/top/tmp.north)+(0,0.5\myfirstlineheight)$) {};
}
{%% node `mynote/top` may or may not be at the bottom of the picture.
%% so create a node that will be at the bottom of the picture
\node[inner sep=0pt] (mynote/bottom) at (current bounding box.south) {};
%% now find out how much space to add to the bottom of the picture
\pgfextracty{\global\mynotebottom}{\pgfpointanchor{mynote/bottom}{south}}
%% uncomment these lines to see some of what was happening.
% \draw[orange!30] (current bounding box.north west) rectangle (current bounding box.south east);
% \draw[blue!30] (mynote/bottom) -- (mynote/top);
% \draw (mynote/bottom) -- ++(0,-1\mynotebottom) -- (mynote/top.south) -- (mynote/bottom.south);
%% by resetting the bounding box at this point, I've basically emulated what
%% an overlay would have done without losing the information I needed to
%% calculate where the bottom of the picture is.
\pgfresetboundingbox
\end{tikzpicture}%%
\vspace{-1\mynotebottom}%%
}
which, if there's following text produces the following sort of result without the user having to do too much more work. Namely, content from the first line of the text following the environment needs to be fed as the second non-optional argument to the environment:
I am doing some calculations here.
\[
\int_SB\cos\alpha\hspace*{1mm}dS \tikzmark{AL}=\tikzmark{AR} B\tikzmark{BL}\cos\alpha\tikzmark{BR}\int_SdS
\]
\begin{mynote}{Lorem ipsum}
.....
\end{mynote}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut
purus elit, vestibulum ut, placerat ac, adipiscing vitae,
felis. Curabitur dictum gravida.
to produce
Thought process behind the update
As already mentioned, the original approach may result in a collision of text and markup.
Not happy!!!
You could, of course, manually enter your own vertical correction. But, what a pain in the neck! It would be nice if this could be done more on the fly, and only require you to manually tweak anything in an odd-ball scenario.
So, I've improved the environment. What I'd really like to do is obtain information from the bounding box. But the overlay
stops the bounding box from even being calculated.
First thought: remove the overlay
from the environment. However, that alone would create an undesirable result:
So the key to emulating overlay
without directly invoking it is to reset the bounding box once everything has been prepared. Since no overlay was used, I have access to the bounding box (before resetting it). Thus, I know where the bottom of the picture is.
Of course, that raises a sticky issue. What if the bottom of the picture is above some other content. If I merely find the bottom of the bounding box, my improvement winds up creating a different kind of collision of text and markup:
This is why at the beginning of the mynote
environment I place a node which is act as a bookmark to remember the height at which this picture was originally created. That way I get a more visually pleasing result.
Using explicit \hspace
commands is rarely required. You probably want that the explanation text is centered below the arrow, so just do it with an array
.
I defined a command in order to avoid complex input.
\documentclass[a4paper,12pt]{article}
\usepackage[utf8]{inputenc} % not required since 2018-04-01
\usepackage[T1]{fontenc} % required for Spanish
\usepackage[spanish]{babel}
\usepackage{amsmath}
\newcommand{\explanation}[3][\Big]{%
\underset{%
\begin{array}{@{}c@{}}
#1\downarrow \\
\makebox[0pt]{\scriptsize #3}
\end{array}
}{#2}%
}
\begin{document}
I am doing some calculations here.
\[
\int_S B\cos\alpha\,dS
\explanation[\bigg]{=}{something happens with $\cos\alpha$}
B\cos\alpha\int_S\,dS
\]
\end{document}
You can also change the size of the arrow with the optional argument (default \Big
).
Note also that in order to separate the differential, \,
(thin space) is much better than \hspace{1mm}
. Also, the T1 encoding is recommended (better, required) for Spanish, or hyphenation would be very problematic.
I think the construct with using \text{...}
is unnecessarily complicate. You could simply have the text outside math mode and place \cos\alpha
as an inline math expression. If you change the font size for this part of the text, the font size of the inline math expression will adjust accordingly:
\documentclass[a4paper,12pt]{article}
\usepackage[spanish]{babel}
\usepackage{amsmath}
\usepackage[utf8]{inputenc}
\begin{document}
I am doing some calculations here.
\[\int_SB\cos\alpha\,dS\underset{\bigg\downarrow}
{=}B\cos\alpha\int_SdS\]
\par\hspace*{4cm} {\footnotesize something happens with $\cos\alpha$}
\end{document}