OMF
unread,Jul 22, 2012, 1:09:32 PM7/22/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to smart-...@googlegroups.com
I have written the following snippet for expanding the \sqrt function in latex. But There are problems when calling the snippet from within itself or any other snippets. ( I have yas/triggers-in-field set)
This function can be called as \sqrt{x} for a square root, or as \sqrt[n]{x} for an nth root. Calling it as \sqrt[]{x} causes problems, so the code below only prints the [] when n is a non-empty string
# -*- mode: snippet -*-
# key: rt
# group: math
# name : \sqrt[n]{x} or \sqrt{x}
# --
\sqrt${1:$(if (string-equal "" yas/text) "" "[")}${1:}${1:$(if (string-equal "" yas/text) "" "]")}{$2}$0
Now, this snippet works perfectly on its own, in latex-mode or using tryout-snippet. Typing
"rt TAB 3 TAB 2 TAB" produces \sqrt[3]{2}
and typing
"rt TAB TAB 2 TAB" produces \sqrt{2}
as expected
However, if it is called from within itself or another snippet, the snippet will not produce the square brackets. For example typing
"rt TAB 3 TAB rt TAB 5 TAB 2 TAB TAB"
produces
\sqrt[3]{\sqrt5{2}}
The yas/text field in the elisp code appears to have been detected as null in the nested snippet call.
Is there a workaround for this behaviour? Is there another yas/variable which contains the text that the elisp could should be calling? Any help would be appreciated.