I'm trying to define a scope for LaTeX subscript/superscript.
The language I have defined is as follows:
{ scopeName = 'text.tex.latex.guido'; fileTypes = ( 'tex' ); patterns = ( { name = 'sscript.math.tex'; match = '(?<!\)(?:_|^){.*}'; }, { include = 'text.tex.latex'; }, { include = 'text.tex.math'; }, ); }
The above language seems to work properly in LaTeX math and LaTeX math environnments. However, the scope is not recognised in plain TeX math, that is in cases like $X_{as}$ shift-ctrl-P does not show the newly defined scope in the tooltip.
I have tried different includes to no avail.
All the best
Guido
-- Dr Guido Governatori School of Information Technology and Electrical Engineering The University of Queensland Brisbane, Queensland, 4072, Australia Phone: +61-(0)7-336 52907 Fax: +61-(0)7-336 54999 http://www.governatori.net/TextMate http://www.defeasible.org
On 11 Nov 2007, at 22:46, Guido Governatori wrote:
[...] The above language seems to work properly in LaTeX math and LaTeX math environnments. However, the scope is not recognised in plain TeX math, that is in cases like $X_{as}$ shift-ctrl-P does not show the newly defined scope in the tooltip.
How exactly are you using this, do you change your top-level language to your new grammar, or do you include the grammar from the default LaTeX grammar?
Either way, I don’t think this can simply be done by adding a new grammar and some includes, instead the existing grammar needs to be changed to support this (but I didn’t look closer into this).
On 12/11/2007, at 2:35 PM, Allan Odgaard wrote:
On 11 Nov 2007, at 22:46, Guido Governatori wrote:
[...] The above language seems to work properly in LaTeX math and LaTeX math environnments. However, the scope is not recognised in plain TeX math, that is in cases like $X_{as}$ shift-ctrl-P does not show the newly defined scope in the tooltip.
How exactly are you using this, do you change your top-level language to your new grammar, or do you include the grammar from the default LaTeX grammar?
I change the top-level grammar to my new one.
Now if I have (X_{as}) the subscript scope defined by the new grammar is shown correctly (same in other math construct), but not in $x_{as}$.
I have an include to text.tex.latex.
I have inserted in the new grammar the definition from string.other.math.tex, and then $X_{as}$ seems to recognised the subscript scope. However, as far as I have seen, it does not recognised in inside section headings.
Either way, I don’t think this can simply be done by adding a new grammar and some includes, instead the existing grammar needs to be changed to support this (but I didn’t look closer into this).
Maybe I have not understood how include, but if I write a grammar where patterns contains only an include statement, don't I "create a copy" of the included grammar under a different name?
All the best
Guido -- Dr Guido Governatori School of Information Technology and Electrical Engineering The University of Queensland Brisbane, Queensland, 4072, Australia Phone: +61-(0)7-336 52907 Fax: +61-(0)7-336 54999 http://www.governatori.net/TextMate http://www.defeasible.org
On 12 Nov 2007, at 06:17, Guido Governatori wrote:
[...] Maybe I have not understood how include, but if I write a grammar where patterns contains only an include statement, don't I "create a copy" of the included grammar under a different name?
Well, you include it, yes.
But if the included grammar does something like “begin = '('; end = ')'; patterns = ( … );” then the rules you put in the grammar where you include the former, will not be active inside (…).
Since LaTeX does a lot of this nesting of rules, it is generally not possible to add a new rule then include the old grammar, and expect the new rule to work in all contexts.
On 13/11/2007, at 4:04 PM, Allan Odgaard wrote:
On 12 Nov 2007, at 06:17, Guido Governatori wrote:
[...] Maybe I have not understood how include, but if I write a grammar where patterns contains only an include statement, don't I "create a copy" of the included grammar under a different name?
Well, you include it, yes.
Allan, thanks for the explanation.
But if the included grammar does something like “begin = '('; end = ')'; patterns = ( … );” then the rules you put in the grammar where you include the former, will not be active inside (…).
I did some experiments, and it seems that it depends whether the inner patterns (...) includes itself or not. Better, if it only includes itself (i.e., $self), then the definition external to the include are not considered in the patterns; if it uses includes = '$base' the external definitions are parsed inside the inner patterns.
Since LaTeX does a lot of this nesting of rules, it is generally not possible to add a new rule then include the old grammar, and expect the new rule to work in all contexts.
I see that in some cases text.tex includes with $self. So scopes with $self cannot be extended while scopes with base can.
All the best
Guido -- Dr Guido Governatori School of Information Technology and Electrical Engineering The University of Queensland Brisbane, Queensland, 4072, Australia Phone: +61-(0)7-336 52907 Fax: +61-(0)7-336 54999 http://www.governatori.net/TextMate http://www.defeasible.org
Guido, I think the grammar you should be adding these constructs to is the TeX Math grammar, since that is the main one that takes effect in math mode. The difference between $self and $base is indeed a delicate one, and the choices we've made are perhaps not always the same. In this case, I think the question is: Should we be allowing arbitrary LaTeX syntax rules inside a math environment? For instance, should we recognize a "\begin{document}...\end{document}" block within a math environment? We opted for "no".
Best, Haris Skiadas Department of Mathematics and Computer Science Hanover College
On Nov 13, 2007, at 3:39 AM, Guido Governatori wrote:
On 13/11/2007, at 4:04 PM, Allan Odgaard wrote:
On 12 Nov 2007, at 06:17, Guido Governatori wrote:
[...] Maybe I have not understood how include, but if I write a grammar where patterns contains only an include statement, don't I "create a copy" of the included grammar under a different name?
Well, you include it, yes.
Allan, thanks for the explanation.
But if the included grammar does something like “begin = '('; end = ')'; patterns = ( … );” then the rules you put in the grammar where you include the former, will not be active inside (…).
I did some experiments, and it seems that it depends whether the inner patterns (...) includes itself or not. Better, if it only includes itself (i.e., $self), then the definition external to the include are not considered in the patterns; if it uses includes = '$base' the external definitions are parsed inside the inner patterns.
Since LaTeX does a lot of this nesting of rules, it is generally not possible to add a new rule then include the old grammar, and expect the new rule to work in all contexts.
I see that in some cases text.tex includes with $self. So scopes with $self cannot be extended while scopes with base can.
All the best
Guido
Dr Guido Governatori School of Information Technology and Electrical Engineering The University of Queensland Brisbane, Queensland, 4072, Australia Phone: +61-(0)7-336 52907 Fax: +61-(0)7-336 54999 http://www.governatori.net/TextMate http://www.defeasible.org