lhs2tex icon indicating copy to clipboard operation
lhs2tex copied to clipboard

`%format pref a = "pref"a` without space in --newcode

Open sgraf812 opened this issue 1 year ago • 2 comments

lhs2TeX is a joy to use, as always, but I'm currently struggling with the following macro:

%if style == newcode
%format (hat (a)) = "__hat" a
%else
%format (hat(a)) = "\widehat{" a "}"

I'm intentionally using hat on identifiers and would have hoped that my newcode definition above makes it so that hat d is emitted as __hatd. Alas, it's actually __hat d. Can I convince lhs2TeX not to emit two separate tokens, or omit the space after "__hat"?

This is somewhat related to https://github.com/kosmikus/lhs2tex/issues/46 and https://github.com/kosmikus/lhs2tex/issues/38, where a quote macro is suggested, which also introduces an additional space. (I'm wondering why that is accepted by the GHC lexer or if I'm doing something wrong.)

sgraf812 avatar Dec 12 '23 17:12 sgraf812

Perhaps this is a bug, as %format suff a = a "__suff"/%format (hat (a)) = a "__hat" works.

sgraf812 avatar Dec 12 '23 17:12 sgraf812

I have to look at the code again, but I think the problem is the way the lexer assigns spaces to the contents of the variable. The space is part of the expansion of a, not part of the macro itself. I believe the workaround is to write hat(d) instead of hat d at the call site.

kosmikus avatar Dec 13 '23 12:12 kosmikus