{-# LANGUAGE OverloadedStrings #-}-- Copyright (C) 2010-2011 John Millikin <jmillikin@gmail.com>---- This program is free software: you can redistribute it and/or modify-- it under the terms of the GNU General Public License as published by-- the Free Software Foundation, either version 3 of the License, or-- any later version.---- This program is distributed in the hope that it will be useful,-- but WITHOUT ANY WARRANTY; without even the implied warranty of-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-- GNU General Public License for more details.---- You should have received a copy of the GNU General Public License-- along with this program. If not, see <http://www.gnu.org/licenses/>.moduleAnansi.Loom.LaTeX(loomLaTeX)whereimportControl.Monad(forM_)importControl.Monad.Reader(asks)importControl.Monad.Writer(tell)importData.ByteString(ByteString)importData.Monoid(mconcat)importqualifiedData.TextimportData.Text(Text)importData.Text.Encoding(encodeUtf8)importAnansi.Types-- | Generate simple, @alltt@-based LaTeX. Users who would like to weave-- specialized LaTeX to fit with their existing templates are encouraged to-- copy this loom and modify it as needed.loomLaTeX::LoomloomLaTeX=mapM_putBlock.documentBlockswhereputBlockb=casebofBlockTexttext->tell(encodeUtf8text)BlockFilepathcontent->dotell"\\begin{alltt}\n"tell"{\\bf\\(\\gg\\) "tell=<<escapepathtell"}\n"putContentcontenttell"\\end{alltt}\n"BlockDefinenamecontent->dotell"\\begin{alltt}\n"tell"{\\bf\\(\\ll\\)"tell=<<escapenametell"\\(\\gg\\)}\n"putContentcontenttell"\\end{alltt}\n"putContentcs=forM_cs$\c->casecofContentText_text->doescapetext>>=telltell"\n"ContentMacro_indentname->formatMacroindentname>>=tellformatMacroindentname=doescIndent<-escapeindentescName<-escapenamereturn(mconcat[escIndent,"|\\emph{",escName,"}|\n"])escape::Text->LoomMByteStringescapetext=dotabSize<-asksloomOptionTabSizereturn$encodeUtf8$Data.Text.concatMap(\c->casecof'\t'->Data.Text.replicate(fromIntegertabSize)" "'\\'->"\\textbackslash{}"'{'->"\\{"'}'->"\\}"'_'->"\\_"_->Data.Text.singletonc)text