MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / cmd

Function cmd

lib/matplotlib/_mathtext.py:1914–1936  ·  view source on GitHub ↗

r""" Helper to define TeX commands. ``cmd("\cmd", args)`` is equivalent to ``"\cmd" - (args | Error("Expected \cmd{arg}{...}"))`` where the names in the error message are taken from element names in *args*. If *expr* already includes arguments (e.g. "\cmd{arg}{...}"), then they

(expr: str, args: ParserElement)

Source from the content-addressed store, hash-verified

1912
1913
1914def cmd(expr: str, args: ParserElement) -> ParserElement:
1915 r"""
1916 Helper to define TeX commands.
1917
1918 ``cmd("\cmd", args)`` is equivalent to
1919 ``"\cmd" - (args | Error("Expected \cmd{arg}{...}"))`` where the names in
1920 the error message are taken from element names in *args*. If *expr*
1921 already includes arguments (e.g. "\cmd{arg}{...}"), then they are stripped
1922 when constructing the parse element, but kept (and *expr* is used as is) in
1923 the error message.
1924 """
1925
1926 def names(elt: ParserElement) -> T.Generator[str, None, None]:
1927 if isinstance(elt, ParseExpression):
1928 for expr in elt.exprs:
1929 yield from names(expr)
1930 elif elt.resultsName:
1931 yield elt.resultsName
1932
1933 csname = expr.split("{", 1)[0]
1934 err = (csname + "".join("{%s}" % name for name in names(args))
1935 if expr == csname else expr)
1936 return csname - (args | Error(f"Expected {err}"))
1937
1938
1939class Parser:

Callers 2

__init__Method · 0.85
deltaMethod · 0.85

Calls 3

namesFunction · 0.85
ErrorFunction · 0.85
joinMethod · 0.80

Tested by

no test coverage detected