Quantcast
Channel: Implement LaTeX accent macros - Code Golf Stack Exchange
Viewing all articles
Browse latest Browse all 6

Answer by nimi for Implement LaTeX accent macros

$
0
0

Haskell, 156 * 0.9 = 140.4 bytes

g('\\':a:r)=(q,l):g s where q|a=='b'='_'|a=='d'='.'|a=='h'='^'|a=='t'='~';(_,_:l:_:s)=span(<'{')rg(a:b)=('',a):g bg""=[('\n','\n')]f=uncurry(++).unzip.g

Usage example:

*Main> putStr $ f "\\dot{L}Vz\\dot{[}|M.\\bar{#}0\\hat{u}U^y!\"\\tilde{I} K.\\bar{\"}\\hat{m}dT\\tilde{$}F\\bar{;}59$,/5\\bar{'}K\\tilde{v}R \\tilde{E}X`".  .   _ ^     ~   _^  ~ _      _ ~  ~  LVz[|M.#0uU^y!"I K."mdT$F;59$,/5'KvR EX`

How it works: go through the input string character by character and build a list of pairs of characters, the left for the upper output string, the right for the lower output string. If a \ is found, take the appropriate accent, else a space for the left element. Finally transform the list of pairs into a single string.


Viewing all articles
Browse latest Browse all 6

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>