Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tex output: formatting expression in a given non-terminal #77

Open
aspiwack opened this issue Apr 8, 2021 · 0 comments
Open

Tex output: formatting expression in a given non-terminal #77

aspiwack opened this issue Apr 8, 2021 · 0 comments

Comments

@aspiwack
Copy link

aspiwack commented Apr 8, 2021

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 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant