1

I'm trying to use a Laplace transform symbol as an operator, so far it looks good, but I want it to be of the same size as the argument that it's working with, so if the argument has one row, the Laplace transform would be of the same hight as one row, and if the argument is a fraction with 2 rows, enlarge the symbol of the operator.

class test2(Scene):
def construct(self):
    my_template = TexTemplate()
    my_template.add_to_preamble(
        r"""
        \usepackage{mathrsfs}
        \let\RSFSmathscr\mathscr  % save the meaning of \mathscr
        \usepackage[scr]{rsfso}
        \let\RSFSOmathscr\mathscr % save the new meaning of \mathscr
        \let\mathscr\RSFSmathscr  % restore the previous meaning
    \newcommand{\Laplace}{\RSFSOmathscr{L}}
    """)
tex = MathTex(r"\Laplace \left \{ \frac{1}{s^2 + 1} \right \}", tex_template=my_template)

and this is the result I'm getting

enter image description here

I would also like to add the arguments t and s, similar to wolfram alpha do it, here is an image of that.

enter image description here

in other words, the final result should look something like this:

enter image description here

I was thinking of maybe something like this?:

            \usepackage{mathrsfs}
            \let\RSFSmathscr\mathscr
            \usepackage[scr]{rsfso}
            \let\RSFSOmathscr\mathscr
            \let\mathscr\RSFSmathscr
        \newcommand{\Laplace}{\RSFSOmathscr{L} _t \left\{ somehow_argument_here  \right \} (s) }

  • In the first picture, you used curly braces after the Laplace symbol. In the second picture, you changed to square brackets. Sometimes you have subscript for the L symbol; sometimes you don't. Can you please clarify which version do you want? – Ruixi Zhang Jan 29 '21 at 22:16
  • the first picture was made by me, the socond didnt, but I want a mix of the 2 with: curly braces, subscript t in the laplace symbol, and I want the laplace symbol as the first pic, also at the end of the argument should be the (s), so I could use for example \Laplace and only indicate the argument \frac{1}{s^2 + 1} – Miguel Fernando Macias Macias Jan 29 '21 at 22:24
  • You are probably looking for this definition then: \newcommand{\Laplace}[2][t]{\mathop{}\!\mathscr{L}_{#1}\!\left\{#2\right\}}. Then in the document body you say \[ \Laplace{ \frac{1}{1+t} }(s) \] or \[ \Laplace{ \sin t }(s) \]. You can even use different arguments such as \[ \Laplace[u]{ \exp(-u) }(x) = \frac{1}{1+x} \] – Ruixi Zhang Jan 29 '21 at 22:40
  • It compiles errors, maybe something with the syntaxis? – Miguel Fernando Macias Macias Jan 29 '21 at 22:48
  • what does \mathop{}\! do? – Miguel Fernando Macias Macias Jan 29 '21 at 22:50
  • My proposed definition of \Laplace takes one mandatory argument, which is the function you throw into the Laplace transform. It also accepts an optional argument, which you can use to replace the subscript. The syntax is \Laplace[<optional arg>]{<mandatory arg>}. – Ruixi Zhang Jan 29 '21 at 22:56
  • im not really sure why but it returns errors even while trying out tex = MathTex(r" \Laplace{ t } ", tex_template=my_template) – Miguel Fernando Macias Macias Jan 29 '21 at 23:02
  • if i understood it, it should use t as a default when you dont use the optional argument, so it shouldnt be neccesary, and let work \Laplace{ t } – Miguel Fernando Macias Macias Jan 29 '21 at 23:04
  • Are you sure you are compiling on LaTeX? \documentclass{article} \usepackage{mathrsfs} \newcommand{\Laplace}[2][t]{\mathop{}\!\mathscr{L}_{#1}\!\left\{#2\right\}} \begin{document} You can write \[ \Laplace{\sin t}(s) \quad\mbox{and}\quad \Laplace{\frac{1}{t+1}}(s) \] \end{document} runs fine on my computer. – Ruixi Zhang Jan 29 '21 at 23:06
  • its manim, but still it acces latex via miktex, so as long as the code works in Latex there shouldnt be any problem – Miguel Fernando Macias Macias Jan 29 '21 at 23:08

3 Answers3

2

You can do this by putting the ℒ and its arguments in boxes, and resizing them. Since you want to be able to add subscripts, I made that an optional argument.

\documentclass{article}
\tracinglostchars=2
\usepackage[paperwidth=10cm]{geometry} % To format the MWE for Tex.SX
\usepackage{iftex} % For \iftutex
\usepackage{settobox} % For \settoboxheight
\usepackage{graphicx} % For \resizebox

\iftutex \usepackage{newcomputermodern} % For example %% By default, \mathscr duplicates \mathcal. You wanted a symbol like %% Boondoxo, which is available as a stylistic set in the STIX fonts. \setmathfont{STIX Two Math}[ Scale=MatchUppercase, StylisticSet=1, range={scr, bfscr}] \else \usepackage{lmodern} % For example \usepackage{amsmath} \usepackage[scr=boondoxo]{mathalpha} \fi

\newlength{\LaplaceHeight} \newbox{\LaplaceArg} \newcommand\Laplace[2][]{% \savebox{\LaplaceArg}{(#2)}% \settoboxheight{\LaplaceHeight}{\LaplaceArg}% \mathop{\resizebox{!}{\LaplaceHeight}{$\mathscr{L}$}}\nolimits_{#1} \usebox{\LaplaceArg}% }

\begin{document} [ \Laplace{\sin t}(s) ]

[ \Laplace[t]{\left{ \frac{1}{t+1} \right} }(s) ] \end{document}

Laplacian sample, on the baseline

This version matches only the height and not the depth. To match your illustration more closely, but drop below the baseline, you can instead resize to the argument’s total height and lower by its depth:

\documentclass{article}
\tracinglostchars=2
\usepackage[paperwidth=10cm]{geometry} % To format the MWE for Tex.SX
\usepackage{iftex} % For \iftutex
\usepackage{settobox} % For \settoboxtotalheight, \settoboxdepth
\usepackage{graphicx} % For \resizebox

\iftutex \usepackage{newcomputermodern} % For example %% By default, \mathscr duplicates \mathcal. You wanted a symbol like %% Boondoxo, which is available as a stylistic set in the STIX fonts. \setmathfont{STIX Two Math}[ Scale=MatchUppercase, StylisticSet=1, range={scr, bfscr}] \else \usepackage{lmodern} % For example \usepackage{amsmath} \usepackage[scr=boondoxo]{mathalpha} \fi

\newlength{\LaplaceHeight} \newlength{\LaplaceDepth} \newbox{\LaplaceArg} \newcommand\Laplace[2][]{% \savebox{\LaplaceArg}{(#2)}% \settoboxtotalheight{\LaplaceHeight}{\LaplaceArg}% \settoboxdepth{\LaplaceDepth}{\LaplaceArg}% \mathop{\raisebox{-\LaplaceDepth}{\resizebox{!}{\LaplaceHeight}{$\mathscr{L}$}}}\nolimits_{#1} \usebox{\LaplaceArg}% }

\begin{document} [ \Laplace{\sin t}(s) ]

[ \Laplace[t]{\lef

Laplacian sample

As several have mentioned in the comments, scaling the ℒ makes it look too heavy. You could possibly scale it only along the vertical axis, but that doesn’t look good either.

Here’s an alternative you might like better, which defines a normal-size \laplace and a double-sized \Laplace, scaling up the latter from a lighter weight of the font family. It requires LuaLaTeX or XeLaTeX.

\documentclass{article}
\tracinglostchars=2

\usepackage{newcomputermodern} % For example \setmathfont{KPMath-Regular}[ Scale=MatchUppercase, range={scr,bfscr}] \setmathfontface\bigmath{KPMath-Light}[Scale=2.0]

\newcommand\laplace{\mathop{\mathscr{L}}\nolimits} \newcommand\Laplace{\mathop{\bigmath{ℒ}}\nolimits}

\begin{document} [ \laplace{\sin t}(s) ]

[ \Laplace_t {\left{ \frac{1}{t+1} \right} }(s) ] \end{document}

KPMath sample

Davislor
  • 44,045
1

Looks like the following code may get to your goal:

\documentclass{article}
\usepackage[scr]{rsfso}
\usepackage{amsmath}
\newcommand{\Laplace}[1]{\mathop{}\!\mathscr{L}_t\!\left\{#1\right\}\!}
\begin{document}
You can write
\[
\Laplace{\sin t}(s)
\quad\text{and}\quad
\Laplace{\frac{1}{t+1}}(s).
\]
Let's leave ``$(s)$'' out of the definition, so you can write
\[
\Laplace{\exp(-t)}(s)=\frac{1}{s+1}
\quad\text{and}\quad
\Laplace{\exp(-t)}(x)=\frac{1}{x+1}.
\]
You can even write some savvy convolution:
\[
\Laplace{(f\ast g)(t)}(s)=\Laplace{f(t)}(s)\Laplace{g(t)}(s),
\]
where $\ast$~is the convolution symbol defined as
\[
(f\ast g)(t)=\int f(x) g(t-x) \, dx.
\]
\end{document}

Laplace

The \mathop{}\! at the very start takes care of spacing (when you write product of Laplace transforms, it adds a tiny amount of space to separate the terms). If you don’t like it, you can remove it. The other two \!’s cancel the extra spaces around \left\{...\right\}.

Ruixi Zhang
  • 9,553
0

The \scalerel macro takes its first argument and scales it to the vertical footprint of the 2nd argument, working in math mode. Adjustments needed were to exclude the _t from the scale calculation, and to have a minimum size of the scale-to footprint, in this case the size of a cap X.

\documentclass{article}
\usepackage{mathrsfs}
  \let\RSFSmathscr\mathscr
  \usepackage[scr]{rsfso}
  \let\RSFSOmathscr\mathscr
  \let\mathscr\RSFSmathscr
\newcommand{\Laplace}[1]{\scalerel{\RSFSOmathscr{L}
  \smash{_t}}{\vphantom{X}#1} (s) }
\usepackage{scalerel}
\begin{document}
\[
\Laplace{\sin t}
\]
\[
\Laplace{\left\{\frac{1}{t^2+1}\right\}}
\]
\end{document}

enter image description here

SUPPLEMENT

The OP asks, I think, if the size of the Laplace operator can be made smaller in the second case, perhaps a fraction of the height of the argument, rather than the full height of the argument. Here, I make it .6 times the height of the argument, with a minimum size corresponding to the size of capital X.

\documentclass{article}
\usepackage{mathrsfs}
  \let\RSFSmathscr\mathscr
  \usepackage[scr]{rsfso}
  \let\RSFSOmathscr\mathscr
  \let\mathscr\RSFSmathscr
\newcommand{\Laplace}[1]{\ThisStyle{
  \sbox0{$\SavedStyle#1$}
  \ht0=.6\ht0
  \dp0=.6\dp0
  \scalerel{\RSFSOmathscr{L}
  \smash{_t}}{\vphantom{X\box0}}#1 (s)}}
\usepackage{scalerel}
\begin{document}
\[
\Laplace{\sin t}
\]
\[
\Laplace{\left\{\frac{1}{t^2+1}\right\}}
\]
\end{document}

enter image description here

  • this one worked like a charm for me, the only things I think could be improved are to make the width of the stroke thinner so that it matches the rest of the expression, and also change a bit the spacing so that the operator isn't as far of the { symbol – Miguel Fernando Macias Macias Jan 30 '21 at 04:04
  • \smash{_t}}{\vphantom{X}#1} this part is for making the _t the size of the capital X right?, if I want to make it half the size of its current height is enough to just change the capital X with normal x? – Miguel Fernando Macias Macias Jan 30 '21 at 04:23
  • @MiguelFernandoMaciasMacias Not exactly. The \smash{_t} removes the subscript from the scaling measurements all together. the \vphantom{X} says to always consider the argument to be at least as tall as an X, and the #1, in addition to typesetting the argument, has it's height used in figuring out how big to make the script-ell. – Steven B. Segletes Jan 30 '21 at 13:38
  • @MiguelFernandoMaciasMacias Please see the supplement to my answer, as a response to what I think you are asking. – Steven B. Segletes Jan 30 '21 at 13:46