You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The problem that I'm facing is the following. Suppose I have, say, grammar rules X and Y
X :: 'X_' ::=
| x :: :: x
| X . Y :: :: prod
Y :: 'Y_' ::=
| y :: :: y
| Y + X :: :: sum
Now, for reasons, I want to highlight all the X things in the Latex output by calling \mathbf around any X tree. Such that, for instance, the Tex output for y + x . y will be roughly y + \mathbf{x . y}.
I don't know how to do this well today. Though I have a bunch of ideas of how Ott could provide this possibility to me
A dedicated homomorphism
Currently, when I write
X :: 'X_' ::= {{ tex \mathbf{[[X]]} }}
Then only the variables X, X1, … get surrounded by \mathbf.
There could be a different homomorphism, say, {{ textformat \mathbf{[[X]]} }} which applies the formatting directive over every subtree of the production X
A level of indirection
Another approach is to add one new non-terminal. The whole grammar then looks like
X :: 'X_' ::=
| x :: :: x
| X . Y :: :: prod
XF :: 'X_' ::=
| X :: :: formatted {{ tex \mathbf[[X]] }}
Y :: 'Y_' ::=
| y :: :: y
| Y + XF :: :: sum
This does work today! The problem that I have, though, is that when I write [[x . y]] in my Latex file, then this will be parsed as X rather than XF. I don't know how rules are chosen, I don't know if this will always be the case, but in some cases at least, it will parse [[x . y]] as an [[X]] hence not apply the formatting (and make me sad).
So, if this were to be the path chosen, I'd need a way to tell my Latex: please don't use X at the toplevel. Much like parsers generators specify their entry point. This may be a desirable feature regardless of my particular use-case, because it may help structure grammars in a number of way (I'm aware of the quotienting-of-grammar feature, it seems to exist to fulfil similar goals, but I don't think it helps here, unless I've missed a trick. There may be a number of ways to do that. Here are some ideas
A homomorphism
I could say something like
X :: 'X_' ::= {{ nottoplevel }}
This would mean that X is not part of the toplevel syntax. I guess it does imply duplicating user_syntax since I understand user_syntax is also used internally. There would be a new toplevel_syntax (name chosen randomly) used by the Tex filter to parse [[…]] directives, and it would be constructed like user_syntax except skipping all the rules with a nottoplevel homomorphism.
A custom entry point
It could, instead, be possible to define a custom entry point non-terminal like is typical of parser generators. In this, I could define my own toplevel_syntax grammar entry. And somehow (either via a command line argument, or via a keyword, or because the grammar entry has a special name) it would be picked up by ott as the rule to parse [[...]] in the Tex filter.
There are a few things to be careful of: this toplevel_syntax non-terminal cannot be just a normal rule, for it must be possible to include the grammars terminals and formula in it, which is not possible in normal user-defined non-terminals.
Final thoughts
I really don't know what would be best, here, but I would really like it if this use-case was supported. I've only recently picked up Ott (only as a paper-writing assistant), and I've got to say: it's a fantastic tool. This is pretty much the one issue I've been having.
Also, if I've missed a trick of the trade, or if I misunderstood something in my characterisations above, do let me know. I'm eager to learn 🙂
The text was updated successfully, but these errors were encountered:
The problem that I'm facing is the following. Suppose I have, say, grammar rules
X
andY
Now, for reasons, I want to highlight all the
X
things in the Latex output by calling\mathbf
around anyX
tree. Such that, for instance, the Tex output fory + x . y
will be roughlyy + \mathbf{x . y}
.I don't know how to do this well today. Though I have a bunch of ideas of how Ott could provide this possibility to me
A dedicated homomorphism
Currently, when I write
Then only the variables
X
,X1
, … get surrounded by\mathbf
.There could be a different homomorphism, say,
{{ textformat \mathbf{[[X]]} }}
which applies the formatting directive over every subtree of the productionX
A level of indirection
Another approach is to add one new non-terminal. The whole grammar then looks like
This does work today! The problem that I have, though, is that when I write
[[x . y]]
in my Latex file, then this will be parsed asX
rather thanXF
. I don't know how rules are chosen, I don't know if this will always be the case, but in some cases at least, it will parse[[x . y]]
as an[[X]]
hence not apply the formatting (and make me sad).So, if this were to be the path chosen, I'd need a way to tell my Latex: please don't use
X
at the toplevel. Much like parsers generators specify their entry point. This may be a desirable feature regardless of my particular use-case, because it may help structure grammars in a number of way (I'm aware of the quotienting-of-grammar feature, it seems to exist to fulfil similar goals, but I don't think it helps here, unless I've missed a trick. There may be a number of ways to do that. Here are some ideasA homomorphism
I could say something like
This would mean that
X
is not part of the toplevel syntax. I guess it does imply duplicatinguser_syntax
since I understanduser_syntax
is also used internally. There would be a newtoplevel_syntax
(name chosen randomly) used by the Tex filter to parse[[…]]
directives, and it would be constructed likeuser_syntax
except skipping all the rules with anottoplevel
homomorphism.A custom entry point
It could, instead, be possible to define a custom entry point non-terminal like is typical of parser generators. In this, I could define my own
toplevel_syntax
grammar entry. And somehow (either via a command line argument, or via a keyword, or because the grammar entry has a special name) it would be picked up byott
as the rule to parse[[...]]
in the Tex filter.There are a few things to be careful of: this
toplevel_syntax
non-terminal cannot be just a normal rule, for it must be possible to include the grammarsterminals
andformula
in it, which is not possible in normal user-defined non-terminals.Final thoughts
I really don't know what would be best, here, but I would really like it if this use-case was supported. I've only recently picked up Ott (only as a paper-writing assistant), and I've got to say: it's a fantastic tool. This is pretty much the one issue I've been having.
Also, if I've missed a trick of the trade, or if I misunderstood something in my characterisations above, do let me know. I'm eager to learn 🙂
The text was updated successfully, but these errors were encountered: