kosmikus / lhs2tex

Preprocessor for typesetting Haskell sources with LaTeX
Other
99 stars 28 forks source link

Can something be done with <$> (infix fmap from Control.Applicative)? Because it looks awful. #58

Open kindaro opened 7 years ago

kindaro commented 7 years ago

This must be an insignificant rant, but can something be done to improve this typesetting?

swaygrab_1509108057-cut

It's way spread out and not nicely vertically aligned: the $ character is way too high up relative to the angle brackets and the rest of the line.

Since <$> made it to Prelude, it sees more use as a nicer replacement for infix `fmap`, so there must be quite a bunch of code around that would benefit from a better out-of-the-box typesetting.

Even just setting <$> in monospace font with some spacing from the surrounding code will make it look better (as you can see throughout this very message). To my knowledge, there's no nice and commonly accepted Unicode codepoint for this operator, but, for example, here on github someone made a set of ligatures that features a nice <$> glyph.

P.S. This typesetting is observed in both poly and math styles.

kosmikus commented 7 years ago

You can just define a formatting directive and map it to anything you like.

ivanperez-keera commented 6 years ago

I agree. It does not look very good. In my opinion, the issues are both height and separation.

For a paper we wrote together, @turion created this rule:

https://github.com/ivanperez-keera/lhs2tex-haskell-operators/blob/master/document.lhs#L16

It looks like this:

untitled

I've created that repo to start collecting these formatting rules. We can keep it simple, just putting them in a versioned file that everyone can download regularly and import for all their projects.

plredmond commented 1 year ago

I use this: $$foo\mathbin{\langle\$\rangle} a \mathbin{\langle*\rangle} b$$

%format <$> = "\mathbin{\langle\$\rangle}"
%format <*> = "\mathbin{\langle*\rangle}"
turion commented 1 year ago

https://github.com/ivanperez-keera/lhs2tex-haskell-operators/blob/master/document.lhs#L16

@ivanperez-keera do you know where this repository is now?

ivanperez-keera commented 1 year ago

I removed the repository because I wasn't using it anymore and didn't know that anybody was. I did not keep a copy, apparently.

I have a copy of our paper and the rule you created was:

%format <$> = "\inanglebrackets{\raisebox{0.1pt}{\scalebox{.8}{\$}}}"

where

\newcommand{\inanglebrackets}[1]{\mathbin{<\hspace{-1.6pt}\mathclap{#1}\hspace{-1.6pt}>}}

Does that help?

turion commented 1 year ago

I did not keep a copy, apparently.

Oh no :(

Does that help?

Yes, that's helpful, thanks! I don't know whether there is interest collecting these formatting rules again and maybe adding them to lhs2tex (optionally)?

ivanperez-keera commented 1 year ago

I'll leave that to you. For the most part, I stopped using lhs2TeX. When using extensions and such it always required too much tweaking and I had to modify my haskell to make it work, which defused the whole purpose :(