Repository: google/latexify_py

Issue:
Ability to get latex without getting function name
```
import latexify
def solve(a):
	return 5 * a
print(latexify.get_latex(solve, no_function=True))
```
to be `5a`, not `\mathrm{solve}(a) \triangleq 5a`

i think it's better to create another function not parameter or set by default

Discussion:

Patch:
diff --git a/examples/equation.ipynb b/examples/examples.ipynb
similarity index 57%
rename from examples/equation.ipynb
rename to examples/examples.ipynb
index 1acfcb2..1c58beb 100644
--- a/examples/equation.ipynb
+++ b/examples/examples.ipynb
@@ -20,17 +20,16 @@
      "output_type": "stream",
      "text": [
       "-1.0\n",
-      "\\mathrm{solve}(a, b, c)\\triangleq \\frac{-b + \\sqrt{b^{2} - 4ac}}{2a}\n",
-      "\n"
+      "\\mathrm{solve}(a, b, c) = \\frac{-b + \\sqrt{b^{{2}} - {4}ac}}{{2}a}\n"
      ]
     },
     {
      "data": {
       "text/latex": [
-       "$$ \\displaystyle \\mathrm{solve}(a, b, c)\\triangleq \\frac{-b + \\sqrt{b^{2} - 4ac}}{2a} $$"
+       "$$ \\displaystyle \\mathrm{solve}(a, b, c) = \\frac{-b + \\sqrt{b^{{2}} - {4}ac}}{{2}a} $$"
       ],
       "text/plain": [
-       "<latexify.core.with_latex.<locals>._LatexifiedFunction at 0x10c803100>"
+       "<latexify.frontend.LatexifiedFunction at 0x7f58824de8f0>"
       ]
      },
      "execution_count": 2,
@@ -39,13 +38,12 @@
     }
    ],
    "source": [
-    "@latexify.with_latex\n",
+    "@latexify.function\n",
     "def solve(a, b, c):\n",
     "    return (-b + math.sqrt(b**2 - 4*a*c)) / (2*a)\n",
     "\n",
     "print(solve(1, 4, 3))\n",
     "print(solve)\n",
-    "print()\n",
     "solve"
    ]
   },
@@ -57,10 +55,10 @@
     {
      "data": {
       "text/latex": [
-       "$$ \\displaystyle \\mathrm{sinc}(x)\\triangleq \\left\\{ \\begin{array}{ll} 1, & \\mathrm{if} \\ x=0 \\\\ \\frac{\\sin{\\left({x}\\right)}}{x}, & \\mathrm{otherwise} \\end{array} \\right. $$"
+       "$$ \\displaystyle \\mathrm{sinc}(x) = \\left\\{ \\begin{array}{ll} {1}, & \\mathrm{if} \\ {x = {0}} \\\\ \\frac{\\sin{\\left({x}\\right)}}{x}, & \\mathrm{otherwise} \\end{array} \\right. $$"
       ],
       "text/plain": [
-       "<latexify.core.with_latex.<locals>._LatexifiedFunction at 0x10c84eaf0>"
+       "<latexify.frontend.LatexifiedFunction at 0x7f58824ddc60>"
       ]
      },
      "execution_count": 3,
@@ -69,7 +67,7 @@
     }
    ],
    "source": [
-    "@latexify.with_latex\n",
+    "@latexify.function\n",
     "def sinc(x):\n",
     "    if x == 0:\n",
     "        return 1\n",
@@ -87,10 +85,10 @@
     {
      "data": {
       "text/latex": [
-       "$$ \\displaystyle \\mathrm{fib}(x)\\triangleq \\left\\{ \\begin{array}{ll} 1, & \\mathrm{if} \\ x=0 \\\\ 1, & \\mathrm{if} \\ x=1 \\\\ \\mathrm{fib}\\left(x - 1\\right) + \\mathrm{fib}\\left(x - 2\\right), & \\mathrm{otherwise} \\end{array} \\right. $$"
+       "$$ \\displaystyle \\mathrm{fib}(x) = \\left\\{ \\begin{array}{ll} {1}, & \\mathrm{if} \\ {x = {0}} \\\\ {1}, & \\mathrm{if} \\ {x = {1}} \\\\ \\mathrm{fib}\\left(x - {1}\\right) + \\mathrm{fib}\\left(x - {2}\\right), & \\mathrm{otherwise} \\end{array} \\right. $$"
       ],
       "text/plain": [
-       "<latexify.core.with_latex.<locals>._LatexifiedFunction at 0x10c85ab50>"
+       "<latexify.frontend.LatexifiedFunction at 0x7f58824de260>"
       ]
      },
      "execution_count": 4,
@@ -100,7 +98,7 @@
    ],
    "source": [
     "# Elif or nested else-if are unrolled.\n",
-    "@latexify.with_latex\n",
+    "@latexify.function\n",
     "def fib(x):\n",
     "    if x == 0:\n",
     "        return 1\n",
@@ -120,10 +118,10 @@
     {
      "data": {
       "text/latex": [
-       "$$ \\displaystyle \\mathrm{greek}({\\alpha}, {\\beta}, {\\gamma}, {\\Omega})\\triangleq {\\alpha}{\\beta} + \\Gamma\\left({{\\gamma}}\\right) + {\\Omega} $$"
+       "$$ \\displaystyle \\mathrm{greek}({\\alpha}, {\\beta}, {\\gamma}, {\\Omega}) = {\\alpha}{\\beta} + \\Gamma\\left({{\\gamma}}\\right) + {\\Omega} $$"
       ],
       "text/plain": [
-       "<latexify.core.with_latex.<locals>._LatexifiedFunction at 0x10c85ae20>"
+       "<latexify.frontend.LatexifiedFunction at 0x7f588226ffa0>"
       ]
      },
      "execution_count": 5,
@@ -133,7 +131,7 @@
    ],
    "source": [
     "# Some math symbols are converted automatically.\n",
-    "@latexify.with_latex\n",
+    "@latexify.function(use_math_symbols=True)\n",
     "def greek(alpha, beta, gamma, Omega):\n",
     "    return alpha * beta + math.gamma(gamma) + Omega\n",
     "\n",
@@ -142,29 +140,36 @@
   },
   {
    "cell_type": "code",
-   "execution_count": null,
+   "execution_count": 6,
    "metadata": {},
-   "outputs": [],
-   "source": []
+   "outputs": [
+    {
+     "data": {
+      "text/latex": [
+       "$$ \\displaystyle \\frac{-b + \\sqrt{b^{{2}} - {4}ac}}{{2}a} $$"
+      ],
+      "text/plain": [
+       "<latexify.frontend.LatexifiedFunction at 0x7f58824de860>"
+      ]
+     },
+     "execution_count": 6,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "# latexify.expression works similarly, but the result does not contain the signature.\n",
+    "@latexify.expression\n",
+    "def solve(a, b, c):\n",
+    "    return (-b + math.sqrt(b**2 - 4*a*c)) / (2*a)\n",
+    "\n",
+    "solve"
+   ]
   }
  ],
  "metadata": {
-  "kernelspec": {
-   "display_name": "Python 3",
-   "language": "python",
-   "name": "python3"
-  },
   "language_info": {
-   "codemirror_mode": {
-    "name": "ipython",
-    "version": 3
-   },
-   "file_extension": ".py",
-   "mimetype": "text/x-python",
-   "name": "python",
-   "nbconvert_exporter": "python",
-   "pygments_lexer": "ipython3",
-   "version": "3.8.5"
+   "name": "python"
   }
  },
  "nbformat": 4,
diff --git a/src/latexify/__init__.py b/src/latexify/__init__.py
index 282c9b4..fc5bc34 100644
--- a/src/latexify/__init__.py
+++ b/src/latexify/__init__.py
@@ -16,4 +16,9 @@
 from latexify import frontend
 
 get_latex = frontend.get_latex
+
+function = frontend.function
+expression = frontend.expression
+
+# Deprecated
 with_latex = frontend.with_latex
diff --git a/src/latexify/codegen/function_codegen.py b/src/latexify/codegen/function_codegen.py
index 9abba0f..ba6fc41 100644
--- a/src/latexify/codegen/function_codegen.py
+++ b/src/latexify/codegen/function_codegen.py
@@ -19,12 +19,14 @@ class FunctionCodegen(ast.NodeVisitor):
 
     _math_symbol_converter: math_symbols.MathSymbolConverter
     _use_raw_function_name: bool
+    _use_signature: bool
 
     def __init__(
         self,
         *,
         use_math_symbols: bool = False,
         use_raw_function_name: bool = False,
+        use_signature: bool = True,
     ) -> None:
         """Initializer.
 
@@ -33,11 +35,14 @@ class FunctionCodegen(ast.NodeVisitor):
                 (e.g., "alpha") to the LaTeX symbol (e.g., "\\alpha").
             use_raw_function_name: Whether to keep underscores "_" in the function name,
                 or convert it to subscript.
+            use_signature: Whether to add the function signature before the expression
+                or not.
         """
         self._math_symbol_converter = math_symbols.MathSymbolConverter(
             enabled=use_math_symbols
         )
         self._use_raw_function_name = use_raw_function_name
+        self._use_signature = use_signature
 
     def generic_visit(self, node: ast.AST) -> str:
         raise exceptions.LatexifyNotSupportedError(
@@ -81,7 +86,9 @@ class FunctionCodegen(ast.NodeVisitor):
         signature_str = name_str + "(" + ", ".join(arg_strs) + ")"
 
         # Function definition: f(x, ...) \triangleq ...
-        return_str = signature_str + " = " + self.visit(return_stmt)
+        return_str = self.visit(return_stmt)
+        if self._use_signature:
+            return_str = signature_str + " = " + return_str
 
         if not body_strs:
             # Only the definition.
diff --git a/src/latexify/frontend.py b/src/latexify/frontend.py
index e6c716d..0a978dc 100644
--- a/src/latexify/frontend.py
+++ b/src/latexify/frontend.py
@@ -4,6 +4,7 @@ from __future__ import annotations
 
 from collections.abc import Callable
 from typing import Any
+import warnings
 
 from latexify import codegen
 from latexify import exceptions
@@ -18,6 +19,7 @@ def get_latex(
     reduce_assignments: bool = False,
     use_math_symbols: bool = False,
     use_raw_function_name: bool = False,
+    use_signature: bool = True,
 ) -> str:
     """Obtains LaTeX description from the function's source.
 
@@ -34,6 +36,8 @@ def get_latex(
             (e.g., "alpha") to the LaTeX symbol (e.g., "\\alpha").
         use_raw_function_name: Whether to keep underscores "_" in the function name,
             or convert it to subscript.
+        use_signature: Whether to add the function signature before the expression or
+            not.
 
     Returns:
         Generatee LaTeX description.
@@ -54,6 +58,7 @@ def get_latex(
     return codegen.FunctionCodegen(
         use_math_symbols=use_math_symbols,
         use_raw_function_name=use_raw_function_name,
+        use_signature=use_signature,
     ).visit(tree)
 
 
@@ -112,8 +117,8 @@ class LatexifiedFunction:
         )
 
 
-def with_latex(*args, **kwargs) -> Callable[[Callable[..., Any]], LatexifiedFunction]:
-    """Translate a function with latex representation.
+def function(*args, **kwargs) -> Callable[[Callable[..., Any]], LatexifiedFunction]:
+    """Translate a function into a corresponding LaTeX representation.
 
     This function works with or without specifying the target function as the positional
     argument. The following two syntaxes works similarly.
@@ -135,3 +140,22 @@ def with_latex(*args, **kwargs) -> Callable[[Callable[..., Any]], LatexifiedFunc
         return LatexifiedFunction(fn, **kwargs)
 
     return wrapper
+
+
+def expression(*args, **kwargs) -> Callable[[Callable[..., Any]], LatexifiedFunction]:
+    """Translate a function into a LaTeX representation without the signature.
+
+    This function is a shortcut for `latexify.function` with the default parameter
+    `use_signature=False`.
+    """
+    kwargs["use_signature"] = kwargs.get("use_signature", False)
+    return function(*args, **kwargs)
+
+
+def with_latex(*args, **kwargs) -> Callable[[Callable[..., Any]], LatexifiedFunction]:
+    """Deprecated. use `latexify.function` instead."""
+    warnings.warn(
+        "`latexify.with_latex` is deprecated. Use `latexify.function` instead.",
+        DeprecationWarning,
+    )
+    return function(*args, **kwargs)


Test patch:
diff --git a/src/integration_tests/regression_test.py b/src/integration_tests/regression_test.py
index 340f5a1..13228b4 100644
--- a/src/integration_tests/regression_test.py
+++ b/src/integration_tests/regression_test.py
@@ -1,4 +1,4 @@
-"""End-to-end test cases of with_latex."""
+"""End-to-end test cases of function."""
 
 from __future__ import annotations
 
@@ -9,7 +9,7 @@ from typing import Any
 from latexify import frontend
 
 
-def _check_with_latex(
+def _check_function(
     fn: Callable[..., Any],
     latex: str,
     **kwargs,
@@ -19,30 +19,30 @@ def _check_with_latex(
     Args:
         fn: Function to check.
         latex: LaTeX form of `fn`.
-        **kwargs: Arguments passed to `frontend.with_latex`.
+        **kwargs: Arguments passed to `frontend.function`.
     """
     # Checks the syntax:
-    #     @with_latex
+    #     @function
     #     def fn(...):
     #         ...
     if not kwargs:
-        latexified = frontend.with_latex(fn)
+        latexified = frontend.function(fn)
         assert str(latexified) == latex
         assert latexified._repr_latex_() == rf"$$ \displaystyle {latex} $$"
 
     # Checks the syntax:
-    #     @with_latex(**kwargs)
+    #     @function(**kwargs)
     #     def fn(...):
     #         ...
-    latexified = frontend.with_latex(**kwargs)(fn)
+    latexified = frontend.function(**kwargs)(fn)
     assert str(latexified) == latex
     assert latexified._repr_latex_() == rf"$$ \displaystyle {latex} $$"
 
     # Checks the syntax:
     #     def fn(...):
     #         ...
-    #     latexified = with_latex(fn, **kwargs)
-    latexified = frontend.with_latex(fn, **kwargs)
+    #     latexified = function(fn, **kwargs)
+    latexified = frontend.function(fn, **kwargs)
     assert str(latexified) == latex
     assert latexified._repr_latex_() == rf"$$ \displaystyle {latex} $$"
 
@@ -52,7 +52,7 @@ def test_quadratic_solution() -> None:
         return (-b + math.sqrt(b**2 - 4 * a * c)) / (2 * a)
 
     latex = r"\mathrm{solve}(a, b, c) = \frac{-b + \sqrt{b^{{2}} - {4}ac}}{{2}a}"
-    _check_with_latex(solve, latex)
+    _check_function(solve, latex)
 
 
 def test_sinc() -> None:
@@ -69,7 +69,7 @@ def test_sinc() -> None:
         r"{x = {0}} \\ \frac{\sin{\left({x}\right)}}{x}, & \mathrm{otherwise} "
         r"\end{array} \right."
     )
-    _check_with_latex(sinc, latex)
+    _check_function(sinc, latex)
 
 
 def test_x_times_beta() -> None:
@@ -77,11 +77,11 @@ def test_x_times_beta() -> None:
         return x * beta
 
     latex_without_symbols = r"\mathrm{xtimesbeta}(x, beta) = xbeta"
-    _check_with_latex(xtimesbeta, latex_without_symbols)
-    _check_with_latex(xtimesbeta, latex_without_symbols, use_math_symbols=False)
+    _check_function(xtimesbeta, latex_without_symbols)
+    _check_function(xtimesbeta, latex_without_symbols, use_math_symbols=False)
 
     latex_with_symbols = r"\mathrm{xtimesbeta}(x, {\beta}) = x{\beta}"
-    _check_with_latex(xtimesbeta, latex_with_symbols, use_math_symbols=True)
+    _check_function(xtimesbeta, latex_with_symbols, use_math_symbols=True)
 
 
 def test_sum_with_limit_1arg() -> None:
@@ -91,7 +91,7 @@ def test_sum_with_limit_1arg() -> None:
     latex = (
         r"\mathrm{sum_with_limit}(n) = \sum_{i = 0}^{{n - 1}} \left({i^{{2}}}\right)"
     )
-    _check_with_latex(sum_with_limit, latex)
+    _check_function(sum_with_limit, latex)
 
 
 def test_sum_with_limit_2args() -> None:
@@ -101,7 +101,7 @@ def test_sum_with_limit_2args() -> None:
     latex = (
         r"\mathrm{sum_with_limit}(a, n) = \sum_{i = a}^{{n - 1}} \left({i^{{2}}}\right)"
     )
-    _check_with_latex(sum_with_limit, latex)
+    _check_function(sum_with_limit, latex)
 
 
 def test_prod_with_limit_1arg() -> None:
@@ -111,7 +111,7 @@ def test_prod_with_limit_1arg() -> None:
     latex = (
         r"\mathrm{prod_with_limit}(n) = \prod_{i = 0}^{{n - 1}} \left({i^{{2}}}\right)"
     )
-    _check_with_latex(prod_with_limit, latex)
+    _check_function(prod_with_limit, latex)
 
 
 def test_prod_with_limit_2args() -> None:
@@ -122,14 +122,14 @@ def test_prod_with_limit_2args() -> None:
         r"\mathrm{prod_with_limit}(a, n) = "
         r"\prod_{i = a}^{{n - 1}} \left({i^{{2}}}\right)"
     )
-    _check_with_latex(prod_with_limit, latex)
+    _check_function(prod_with_limit, latex)
 
 
 def test_nested_function() -> None:
     def nested(x):
         return 3 * x
 
-    _check_with_latex(nested, r"\mathrm{nested}(x) = {3}x")
+    _check_function(nested, r"\mathrm{nested}(x) = {3}x")
 
 
 def test_double_nested_function() -> None:
@@ -139,20 +139,20 @@ def test_double_nested_function() -> None:
 
         return inner
 
-    _check_with_latex(nested(3), r"\mathrm{inner}(y) = xy")
+    _check_function(nested(3), r"\mathrm{inner}(y) = xy")
 
 
 def test_use_raw_function_name() -> None:
     def foo_bar():
         return 42
 
-    _check_with_latex(foo_bar, r"\mathrm{foo_bar}() = {42}")
-    _check_with_latex(
+    _check_function(foo_bar, r"\mathrm{foo_bar}() = {42}")
+    _check_function(
         foo_bar,
         r"\mathrm{foo_bar}() = {42}",
         use_raw_function_name=False,
     )
-    _check_with_latex(
+    _check_function(
         foo_bar,
         r"\mathrm{foo\_bar}() = {42}",
         use_raw_function_name=True,
@@ -164,11 +164,11 @@ def test_reduce_assignments() -> None:
         a = x + x
         return 3 * a
 
-    _check_with_latex(
+    _check_function(
         f,
         r"\begin{array}{l} a = x + x \\ \mathrm{f}(x) = {3}a \end{array}",
     )
-    _check_with_latex(f, r"\mathrm{f}(x) = {3}(x + x)", reduce_assignments=True)
+    _check_function(f, r"\mathrm{f}(x) = {3}(x + x)", reduce_assignments=True)
 
 
 def test_reduce_assignments_double() -> None:
@@ -185,9 +185,9 @@ def test_reduce_assignments_double() -> None:
         r"\end{array}"
     )
 
-    _check_with_latex(f, latex_without_option)
-    _check_with_latex(f, latex_without_option, reduce_assignments=False)
-    _check_with_latex(
+    _check_function(f, latex_without_option)
+    _check_function(f, latex_without_option, reduce_assignments=False)
+    _check_function(
         f,
         r"\mathrm{f}(x) = {3}(x^{{2}} + x^{{2}})",
         reduce_assignments=True,
@@ -203,7 +203,7 @@ def test_reduce_assignments_with_if() -> None:
         else:
             return n
 
-    _check_with_latex(
+    _check_function(
         sigmoid,
         (
             r"\mathrm{sigmoid}(x) = \left\{ \begin{array}{ll} "
diff --git a/src/latexify/codegen/function_codegen_test.py b/src/latexify/codegen/function_codegen_test.py
index 45ef960..78d87df 100644
--- a/src/latexify/codegen/function_codegen_test.py
+++ b/src/latexify/codegen/function_codegen_test.py
@@ -8,7 +8,7 @@ from latexify import test_utils
 
 import pytest
 
-from latexify.codegen import function_codegen
+from latexify.codegen import FunctionCodegen, function_codegen
 
 
 def test_generic_visit() -> None:
@@ -22,6 +22,25 @@ def test_generic_visit() -> None:
         function_codegen.FunctionCodegen().visit(UnknownNode())
 
 
+def test_visit_functiondef_use_signature() -> None:
+    tree = ast.FunctionDef(
+        name="f",
+        args=ast.arguments(
+            args=[ast.arg(arg="x")],
+            kwonlyargs=[],
+            kw_defaults=[],
+            defaults=[],
+        ),
+        body=[ast.Return(value=ast.Name(id="x", ctx=ast.Load()))],
+        decorator_list=[],
+    )
+    latex_without_flag = "x"
+    latex_with_flag = r"\mathrm{f}(x) = x"
+    assert FunctionCodegen().visit(tree) == latex_with_flag
+    assert FunctionCodegen(use_signature=False).visit(tree) == latex_without_flag
+    assert FunctionCodegen(use_signature=True).visit(tree) == latex_with_flag
+
+
 @pytest.mark.parametrize(
     "code,latex",
     [
diff --git a/src/latexify/frontend_test.py b/src/latexify/frontend_test.py
index af1ef78..60ceed5 100644
--- a/src/latexify/frontend_test.py
+++ b/src/latexify/frontend_test.py
@@ -5,15 +5,129 @@ from __future__ import annotations
 from latexify import frontend
 
 
-def test_identifiers() -> None:
-    def very_long_name_function(very_long_name_variable):
-        return 3 * very_long_name_variable
+def test_get_latex_identifiers() -> None:
+    def myfn(myvar):
+        return 3 * myvar
 
-    identifiers = {
-        "very_long_name_function": "f",
-        "very_long_name_variable": "x",
-    }
+    identifiers = {"myfn": "f", "myvar": "x"}
 
-    assert frontend.get_latex(very_long_name_function, identifiers=identifiers) == (
-        r"\mathrm{f}(x) = {3}x"
+    latex_without_flag = r"\mathrm{myfn}(myvar) = {3}myvar"
+    latex_with_flag = r"\mathrm{f}(x) = {3}x"
+
+    assert frontend.get_latex(myfn) == latex_without_flag
+    assert frontend.get_latex(myfn, identifiers=identifiers) == latex_with_flag
+
+
+def test_get_latex_reduce_assignments() -> None:
+    def f(x):
+        y = 3 * x
+        return y
+
+    latex_without_flag = r"\begin{array}{l} y = {3}x \\ \mathrm{f}(x) = y \end{array}"
+    latex_with_flag = r"\mathrm{f}(x) = {3}x"
+
+    assert frontend.get_latex(f) == latex_without_flag
+    assert frontend.get_latex(f, reduce_assignments=False) == latex_without_flag
+    assert frontend.get_latex(f, reduce_assignments=True) == latex_with_flag
+
+
+def test_get_latex_use_math_symbols() -> None:
+    def f(alpha):
+        return alpha
+
+    latex_without_flag = r"\mathrm{f}(alpha) = alpha"
+    latex_with_flag = r"\mathrm{f}({\alpha}) = {\alpha}"
+
+    assert frontend.get_latex(f) == latex_without_flag
+    assert frontend.get_latex(f, use_math_symbols=False) == latex_without_flag
+    assert frontend.get_latex(f, use_math_symbols=True) == latex_with_flag
+
+
+def test_get_latex_use_raw_function_name() -> None:
+    def foo_bar(x):
+        return x
+
+    latex_without_flag = r"\mathrm{foo_bar}(x) = x"
+    latex_with_flag = r"\mathrm{foo\_bar}(x) = x"
+
+    assert frontend.get_latex(foo_bar) == latex_without_flag
+    assert (
+        frontend.get_latex(foo_bar, use_raw_function_name=False) == latex_without_flag
     )
+    assert frontend.get_latex(foo_bar, use_raw_function_name=True) == latex_with_flag
+
+
+def test_get_latex_use_signature() -> None:
+    def f(x):
+        return x
+
+    latex_without_flag = "x"
+    latex_with_flag = r"\mathrm{f}(x) = x"
+
+    assert frontend.get_latex(f) == latex_with_flag
+    assert frontend.get_latex(f, use_signature=False) == latex_without_flag
+    assert frontend.get_latex(f, use_signature=True) == latex_with_flag
+
+
+def test_function() -> None:
+    def f(x):
+        return x
+
+    latex_without_flag = "x"
+    latex_with_flag = r"\mathrm{f}(x) = x"
+
+    # Checks the syntax:
+    #     @function
+    #     def fn(...):
+    #         ...
+    latexified = frontend.function(f)
+    assert str(latexified) == latex_with_flag
+    assert latexified._repr_latex_() == rf"$$ \displaystyle {latex_with_flag} $$"
+
+    # Checks the syntax:
+    #     @function(**kwargs)
+    #     def fn(...):
+    #         ...
+    latexified = frontend.function(use_signature=False)(f)
+    assert str(latexified) == latex_without_flag
+    assert latexified._repr_latex_() == rf"$$ \displaystyle {latex_without_flag} $$"
+
+    # Checks the syntax:
+    #     def fn(...):
+    #         ...
+    #     latexified = function(fn, **kwargs)
+    latexified = frontend.function(f, use_signature=False)
+    assert str(latexified) == latex_without_flag
+    assert latexified._repr_latex_() == rf"$$ \displaystyle {latex_without_flag} $$"
+
+
+def test_expression() -> None:
+    def f(x):
+        return x
+
+    latex_without_flag = "x"
+    latex_with_flag = r"\mathrm{f}(x) = x"
+
+    # Checks the syntax:
+    #     @expression
+    #     def fn(...):
+    #         ...
+    latexified = frontend.expression(f)
+    assert str(latexified) == latex_without_flag
+    assert latexified._repr_latex_() == rf"$$ \displaystyle {latex_without_flag} $$"
+
+    # Checks the syntax:
+    #     @expression(**kwargs)
+    #     def fn(...):
+    #         ...
+    latexified = frontend.expression(use_signature=True)(f)
+    assert str(latexified) == latex_with_flag
+    assert latexified._repr_latex_() == rf"$$ \displaystyle {latex_with_flag} $$"
+
+    # Checks the syntax:
+    #     def fn(...):
+    #         ...
+    #     latexified = expression(fn, **kwargs)
+    latexified = frontend.expression(f, use_signature=True)
+    assert str(latexified) == latex_with_flag
+    assert latexified._repr_latex_() == rf"$$ \displaystyle {latex_with_flag} $$"