title: $:/plugins/tiddlywiki/katex/ui/config/macro tags: $:/tags/KaTeX/Config caption: Custom macro editor \define katex-escape(text) <$vars t=$text$> <$latex text={{{[search-replace:g:regexp[(? \end \define katex-create-macro() <$vars loc={{$:/temp/katex/new-macro-name}}> <$action-createtiddler $basetitle={{{[addprefix[$:/plugins/tiddlywiki/katex/macros/]]}}} tags="$:/tags/KaTeX/Macro" type="text/plain" caption={{$:/temp/katex/new-macro-name}} text={{$:/temp/katex/new-macro-command}} $overwrite=yes/> \end \define katex-edit-cell() <$reveal state="$:/temp/katex/edit-macro" type=match text={{!!title}}> <$edit-text tiddler=<> tag="input" default=""/> \end \define katex-view-cell() <$reveal state="$:/temp/katex/edit-macro" type=nomatch text={{!!title}}> <$view field=text/> \end \define katex-edit-macro-button() <$reveal state="$:/temp/katex/edit-macro" type=nomatch text={{!!title}}> <$button class="tc-btn-invisible tc-btn-dropdown"> <$action-setfield $tiddler="$:/temp/katex/edit-macro" text={{!!title}}/> {{$:/core/images/edit-button}} \end \define katex-save-macro-button() <$reveal state="$:/temp/katex/edit-macro" type=match text={{!!title}}> <$button class="tc-btn-invisible tc-btn-dropdown"> <$action-deletetiddler $tiddler="$:/temp/katex/edit-macro"/> {{$:/core/images/done-button}} \end <$list filter="[all[shadows+tiddlers]tag[$:/tags/KaTeX/Macro]!has[draft.of]sort[caption]]">
Macro Command Preview
<$text text={{!!caption}}/> <><> <> <> <> <$button class="tc-btn-invisible tc-btn-dropdown"> <$action-deletetiddler $tiddler={{!!title}}/> {{$:/core/images/delete-button}}
Add a new macro
<$edit-text tiddler="$:/temp/katex/new-macro-name" tag="input" default=""/> <$edit-text tiddler="$:/temp/katex/new-macro-command" tag="input" default=""/> <> <$button actions=<>> {{$:/language/EditTemplate/Fields/Add/Button}}
Import <$edit-text tiddler="$:/temp/katex/import-macro" tag="textarea" default="" class="tc-edit-texteditor" placeholder="You can type commands like \def\ZZ{\mathbb{Z}} and import them automatically."/> <$vars macros={{$:/temp/katex/import-macro}} sep="%.*\n|\n+" re="^\\g?def([^{]*){(.*)}.*"> <$button> <$list filter="[splitregexpregexp]" variable=line> <$vars m={{{[search-replace:g:regexp,[$1]]}}} c={{{[search-replace:g:regexp,[$2]]}}}> <$action-createtiddler $basetitle={{{[addprefix[$:/plugins/tiddlywiki/katex/macros/]]}}} tags="$:/tags/KaTeX/Macro" type="text/plain" caption=<> text=<> $overwrite=yes/> Import <$button> <$action-setfield $tiddler="$:/temp/katex/import-macro" text=""/> Clear ''Preview'' <$list filter="[splitregexpregexp]" variable=line> <$vars m={{{[search-replace:g:regexp,[$1]]}}} c={{{[search-replace:g:regexp,[$2]]}}}>
<> <> <$macrocall $name=katex-escape text="<>"/>
Usage
  • You can add entries like `\ZZ`, `\mathbb{Z}`, which will render as <$latex text="\mathbb{Z}"/>.
  • An entry mapping `\dd#1#2` to `\frac{d#1}{d#2}` will create a macro with two arguments; `\dd{f}{x}` will then render as <$latex text="\frac{df}{dx}"/>.
  • Note that the macros defined here have higher priority than those defined using `\gdef`. Also, deleted macros will continue to exist until a full refresh.