tbl.fun 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #import std
  2. #import nat
  3. #comment -[
  4. This module contains some functions for generating tables in LaTeX
  5. format.
  6. Copyright (C) 2007-2010 Dennis Furey]-
  7. #optimize+
  8. headings = # takes a list of trees of lists of strings to the latex code for some table headings
  9. %sLMk+ -+
  10. (~&aatPB^?\~&a ~&ath=='&'?/~&fahthPTttPCPR ~&ahPfatPRC)+ *= =]'\cmid'?\~&iNC sep` ,
  11. ~&NiX; ~&ly+ %sLnsLXTLXMk+ ~&rdrPk-> ^(
  12. ^T\~&l (~&r; *= ~&a^& ~&av?/~&favPML ~&adNC); %nsLXLMk; ^T(
  13. ^lrNCT(~&y,--'\\'+ ~&z)+ mat'&'+ * ~&i&& -+
  14. 1?=l/~&r ~&rZ?/(~&iiNCB+ `&!*+ ~&t+ iota+ ~&l) ^lrhPTrtPC(
  15. '\multicolumn{'--+ --'}{c}'+ ~&h+ %nP+ ~&l,
  16. :^(:/`{+ ~&h,~&t)+ ^lrNCT/~&ry --'}'+ ~&rz),
  17. ^/~&l ~&r; ~&i&& ~&t?\~& :/'\begin{tabular}{c}'+ --<'\end{tabular}$\!\!\!\!$'>+ ^T(~&y; * --'\\',~&zNC)+-,
  18. ~&iNC+ mat` + ~&rFlS+ ^p\~&rS ~&lS; (* '\cmidrule'--)+ -+
  19. (~&titB?\~& :^/~&h ~&t; ^T\~&zNC ~&y; * '(lr)'--)+ :^('(r)'--+ ~&h,~&t)+ ^lrNCT(~&y,'(l)'--+ ~&z),
  20. * :/`{+ --'}'+ ^T(~&l,:/`-+ ~&r)+ ~~ ~&h+ %nP,
  21. :/0; ~&ar^& :^(^/successor+~&al sum+~&alrhPX,^R/~&f ^/sum+~&alrhPX ~&art)+-),
  22. ~&r; * ~&a^& ~&av?\~&adlPNXNV ^V/~&ad ~&favPM; &&~& any~&dr),
  23. %nsLXTLMk+ * ~&a^& ~&av?\-+~&V\<>+ ~&/1+ ~&ad+- ~&adPfavPMV; ^V\~&v ^\~&d sum:-0+ ~&vdlPS+-
  24. body = # takes a list of string lists or float lists to a latex table body
  25. "d". -+
  26. (* --'\\')+ (* :-0 ^|T/~& ' & '--)+ transpose+ (~&rS+ zipp '')^*D\~& leql$^,
  27. * scientific_notation*+ %sLI?/~& * -+
  28. ==` -~; ^T/~&l ~&r; -!~&h~=`-,~&c/'123456789'!-?/~& :/` + ~&t,
  29. =='inf'?/'$\infty$'! =='-inf'?/'$-\infty$'! ~&,
  30. //(library/'math' 'asprintf') '%0.'-- --'f' ~&h %nP "d"+-+-
  31. #library+
  32. vwrap "n" = # takes a table argument and splits it n ways side by side, eliminating repeated columns
  33. -+
  34. ^|\~& ~&dvihBPCoS; (rlc eql); *= ~&aht^?\~&a ^JalSPfarSPMp/~&f ~&hhPtSXS+ rlc~&EbhPO+ ~&a,
  35. (~&rSlSrSX+ nleq-<&l+ |=hS&r+ num)^lvdvDiNCQoSL2rp/(~&DlSL\iota"n"+ ~&l) ~&rSS+ zipp0^*D(leql$^,~&)^HK7L(
  36. *+ block+ ~&r?(~&l,predecessor+ ~&l)+ division\"n"+ sum/"n"+ nleq$^+ length*+ ~&r,
  37. ~&r; ~&rSS+ zipp0^*D\~& leql$^)+-
  38. scientific_notation = # changes a floating point string of the form d.dE+d to d.d x 10^d in LaTeX format
  39. -=/`$?/~& ~&aitB^?\~&a ?(
  40. -&~&ah-='eE',~&ath-='+-',~&att; ~&i&& all -=\'0123456789'&-,
  41. ~&\~&ahPfatPRC '$\times 10^{'--+ --'}$'+ ^T/-&~&ath==`-,~&athNC&- ~&att; ||('0'!) ->~&t ~&i&& ~&h==`0)
  42. table = # takes the number of decimal places to a function taking (headings,<column..>) of type %sLTLeLsLULX
  43. "d". :^/('\begin{tabular}{'--+ --'}'+ `r!*+ ~&r) --<'\end{tabular}',''>+ :/'\toprule'+ --<'\bottomrule'>+ ^|T(
  44. --<'\midrule'>+ headings,
  45. body "d")
  46. sectioned_table = # takes the number of decimal places to a function taking (headings,<<column..>..>) of type %sLTLeLsLULLX
  47. "d". :^(
  48. '\begin{tabular}{'--+ --'}'+ `r!*+ ~&rihB,
  49. --<'\end{tabular}',''>+ :/'\toprule'+ --<'\bottomrule'>+ ^|T(--<'\midrule'>+ headings,mat'\midrule'+ * body "d"))
  50. elongation = # takes a caption to a function changing a table generated by the table function to longtable format
  51. ^rlPlrrPNCTCNNCT(~&tyy,~&hyzPX; ~~ 'tabular'%='longtable')++ -+.
  52. ~&?(
  53. "c". :^/~&h ~&t; ~='\midrule'-~; ~&lrhPNCTrtPX; ^T\~&r ~&l; ^T(
  54. :/('\caption{'--"c"--'}\\')+ --<'\endfirsthead'>,
  55. :/('\caption{'--"c"--' (continued)}\\')+ --<'\endhead','\bottomrule','\endfoot'>),
  56. ! ~&a^& '\midrule'?=ah\~&ahPfatPRC <'\midrule','\endhead','\bottomrule','\endfoot'>--+ ~&at),
  57. ! *~ ~='\bottomrule'+-
  58. label = # takes a label to a function that adds a label to the result of an elongation
  59. ('\label{'--+ --'}'); "s". *= '\endfoot'?=\~&iNC :\<"s">