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

Answer by Reto Koradi for Implement LaTeX accent macros

$
0
0

CJam, 53 bytes

Sl+'\/(_,S*\@{(i2/49-"_. ^"=\3>'}-_,(S*@\+@@+@@+\}/N\

Try it online

Explanation:

S       Leading space, to avoid special case for accent at start.l+      Get input, and append it to leading space.'\/     Split at '\.(       Split off first sub-string, which does not start with an accent._,      Get length of first sub-string.S*      String of spaces with the same length.\       Swap the two. First parts of both output lines are now on stack.@       Rotate list of remaining sub-strings to top.{       Loop over sub-strings.  (       Pop first character. This is 'b, 'd, or 'h, and determines accent.  i       Convert to integer.  2/      Divide by two.  49-     Subtract 49. This will result in 0, 1, or 4 for the different accents."_. ^"  Lookup string for the accents.  =       Get the correct accent.  \       Swap string to top.  3>      Remove the first 3 characters, which is the rest of the accent string          and the '{.'}-     Remove the '}. All the macro stuff is removed now.  _,(     Get the length, and subtract 1. This is the number of spaces for the first line.  S*      Produce the spaces needed for the first line.  @\+     Bring accent and spaces to top, and concatenate them.  @@+     Get previous second line and new sub-string without formatting to top,          and concatenate them.  @@+     Get previous first line and new accent and spacing to top,          and concatenate them.  \       Swap the two lines to get them back in first/second order.}/      End loop over sub-strings.N\      Put newline between first and second line.

Viewing all articles
Browse latest Browse all 6

Trending Articles



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