0

So I'm writing my master thesis and I was wondering whether there was a way to script a custom \Laplace function in Latex. I want to write \Laplace(input) and get the output \Laplace \{ input \} as my Latex output. My function is defined like this now

\newcommand{\Laplace}{\mathscr{L}}

. Instead of writing \Laplace \{ input \} on every place I need my Laplace

Bernard
  • 271,350

1 Answers1

3

We can define it as \newcommand\Laplace[1]{\ensuremath{\mathscr{L}\mleft\{#1\mright\}}} where the \mleft\{ and \mright\} will make the braces scale appropriately with taller arguments.

\documentclass{article}
\usepackage{amsmath}
\usepackage{mathrsfs}
\usepackage{mleftright}
\newcommand\Laplace[1]{\ensuremath{\mathscr{L}\mleft\{#1\mright\}}}
\begin{document}
\begin{align*}
\Laplace{\delta(t)}&=1\\
\Laplace{\frac{1}{(n-1)!}t^{n-1}e^{-at}}&=\frac{1}{(s+a)^n}\\
\end{align*}
\end{document}

enter image description here

It might be useful to define an inverse laplace command as well: \newcommand\InvLaplace[1]{\ensuremath{\mathscr{L}^{-1}\mleft\{#1\mright\}}}

EDIT: Thanks to @Mico for recommending \mleft and \mright from mleftright for removing the extra space between the Laplace operator and the start of the braces.

Dan
  • 3,699
  • When i use this in my document i get a new page on the top. and say Laplace symbol {1 } on that page. And also when i use it in the document i dont get the braces around it – Lopehert Nov 16 '21 at 21:45
  • 1
    The use of \left\{ creates too much whitespace between \mathscr{L} and \{. (Check out \ln(x) or \sin(theta) -- it's no accident that there's no whitespace between the function name and the parenthesis.) To get around this problem, you could load the mleftright package and replace \left\{#1\right\} with \mleft\{#1\mright\}. – Mico Nov 16 '21 at 22:01
  • 1
    @Mico Thanks! I just updated the answer to include mleftright. – Dan Nov 16 '21 at 22:08
  • @Lopehert the code here should work, you could add a similar small example to your question that shows your problem – David Carlisle Nov 16 '21 at 22:09
  • 1
    +1: I did not know about the mleftright package, good to know. – Dr. Manuel Kuehner Nov 16 '21 at 22:27
  • Works now! Thanks alot :) – Lopehert Nov 16 '21 at 22:27
  • What is the reason for using the mathrsfs package? It seems to ver quite old (1999?). – Dr. Manuel Kuehner Nov 16 '21 at 22:28
  • 1
    @Dr.ManuelKuehner It is for the \mathscr "L", though perhaps there is a newer package for it that I don't yet know about. – Dan Nov 16 '21 at 22:30
  • 4
    @Dr.ManuelKuehner - The mathrsfs -- "rsfs" is short for "Ralph Smith's formal script" -- math font package provides heavily sloped "script"-style uppercase letters. The fact that the .sty file hasn't been updated in 20 years is of little consequence. – Mico Nov 16 '21 at 22:32