Skip to content
This repository has been archived by the owner on Mar 7, 2018. It is now read-only.

Commit

Permalink
Added LaTeX output for rules.
Browse files Browse the repository at this point in the history
  • Loading branch information
tpapp committed Oct 11, 2012
1 parent 2efae59 commit 671c4e0
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions latex-table.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,22 @@ Filespecs are opened, streams are used as is."
(:method ((cell string))
(dump cell)))

(defun latex-rule (rule)
"Return LaTeX code representing rule as a string."
(ecase rule
(:top "\\toprule")
(:bottom "\\bottomrule")
(:middle "\\midrule")))

(defgeneric write-latex (filespec-or-stream table)
(:documentation "Write TABLE to FILESPEC-OR-STREAM for LaTeX.")
(:method (filespec-or-stream (raw-table raw-table))
(let+ (((&slots-r/o column-types cells) raw-table)
((nrow ncol) (array-dimensions cells)))
(let+ (((&slots-r/o column-types cells rules) raw-table)
((nrow ncol) (array-dimensions cells))
((&flet dump-rule (row-index)
(awhen (aref rules row-index)
(dump (latex-rule it))
(fresh)))))
(with-output (filespec-or-stream)
(fresh)
(dump "\\begin{tabular}{")
Expand All @@ -306,6 +317,7 @@ Filespecs are opened, streams are used as is."
(dump "}")
(loop for row-index below nrow
do (fresh)
(dump-rule row-index)
(loop for col-index below ncol
for column-type across column-types
do (let ((cell (aref cells row-index col-index)))
Expand All @@ -316,6 +328,7 @@ Filespecs are opened, streams are used as is."
(when (= col-index (1- ncol))
(dump " \\\\"))))
(fresh)
(dump-rule nrow)
(dump "\\end{tabular}")
(fresh))))
(:method (filespec-or-stream (table table))
Expand Down

0 comments on commit 671c4e0

Please sign in to comment.