{-
Copyright (C) 2007-2010 John MacFarlane <jgm@berkeley.edu>
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 2 of the License, or
(at your option) 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, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-}{- |
Module : Text.Pandoc.Readers.TeXMath
Copyright : Copyright (C) 2007-2010 John MacFarlane
License : GNU GPL, version 2 or above
Maintainer : John MacFarlane <jgm@berkeley.edu>
Stability : alpha
Portability : portable
Conversion of TeX math to a list of 'Pandoc' inline elements.
-}moduleText.Pandoc.Readers.TeXMath(readTeXMath)whereimportText.Pandoc.DefinitionimportText.TeXMath.TypesimportText.TeXMath.Parser-- | Converts a raw TeX math formula to a list of 'Pandoc' inlines.-- Defaults to raw formula between @$@ characters if entire formula-- can't be converted.readTeXMath::String-- ^ String to parse (assumes @'\n'@ line endings)->[Inline]readTeXMathinp=casetexMathToPandocinpofLeft_->[Str("$"++inp++"$")]Rightres->restexMathToPandoc::String->EitherString[Inline]texMathToPandocinp=inp`seq`caseparseFormulainpofLefterr->LefterrRightexps->caseexpsToInlinesexpsofNothing->Left"Formula too complex for [Inline]"Justr->RightrexpsToInlines::[Exp]->Maybe[Inline]expsToInlinesxs=dores<-mapMexpToInlinesxsreturn(concatres)expToInlines::Exp->Maybe[Inline]expToInlines(ENumbers)=Just[Strs]expToInlines(EIdentifiers)=Just[Emph[Strs]]expToInlines(EMathOperators)=Just[Strs]expToInlines(ESymbolts)=Just$addSpacet(Strs)whereaddSpaceOpx=[x,thinspace]addSpaceBinx=[medspace,x,medspace]addSpaceRelx=[widespace,x,widespace]addSpacePunx=[x,thinspace]addSpace_x=[x]thinspace=Str"\x2006"medspace=Str"\x2005"widespace=Str"\x2004"expToInlines(EStretchyx)=expToInlinesxexpToInlines(EDelimitedstartendxs)=doxs'<-mapMexpToInlinesxsreturn$[Strstart]++concatxs'++[Strend]expToInlines(EGroupedxs)=expsToInlinesxsexpToInlines(ESpace"0.167em")=Just[Str"\x2009"]expToInlines(ESpace"0.222em")=Just[Str"\x2005"]expToInlines(ESpace"0.278em")=Just[Str"\x2004"]expToInlines(ESpace"0.333em")=Just[Str"\x2004"]expToInlines(ESpace"1em")=Just[Str"\x2001"]expToInlines(ESpace"2em")=Just[Str"\x2001\x2001"]expToInlines(ESpace_)=Just[Str" "]expToInlines(EBinary___)=NothingexpToInlines(ESubxy)=dox'<-expToInlinesxy'<-expToInlinesyreturn$x'++[Subscripty']expToInlines(ESuperxy)=dox'<-expToInlinesxy'<-expToInlinesyreturn$x'++[Superscripty']expToInlines(ESubsupxyz)=dox'<-expToInlinesxy'<-expToInlinesyz'<-expToInlineszreturn$x'++[Subscripty']++[Superscriptz']expToInlines(EDownxy)=expToInlines(ESubxy)expToInlines(EUpxy)=expToInlines(ESuperxy)expToInlines(EDownupxyz)=expToInlines(ESubsupxyz)expToInlines(ETextTextNormalx)=Just[Strx]expToInlines(ETextTextBoldx)=Just[Strong[Strx]]expToInlines(ETextTextMonospacex)=Just[CodenullAttrx]expToInlines(ETextTextItalicx)=Just[Emph[Strx]]expToInlines(EText_x)=Just[Strx]expToInlines(EOver(EGrouped[EIdentifier[c]])(ESymbolAccent[accent]))=caseaccentof'\x203E'->Just[Emph[Str[c,'\x0304']]]-- bar'\x00B4'->Just[Emph[Str[c,'\x0301']]]-- acute'\x0060'->Just[Emph[Str[c,'\x0300']]]-- grave'\x02D8'->Just[Emph[Str[c,'\x0306']]]-- breve'\x02C7'->Just[Emph[Str[c,'\x030C']]]-- check'.'->Just[Emph[Str[c,'\x0307']]]-- dot'\x00B0'->Just[Emph[Str[c,'\x030A']]]-- ring'\x20D7'->Just[Emph[Str[c,'\x20D7']]]-- arrow right'\x20D6'->Just[Emph[Str[c,'\x20D6']]]-- arrow left'\x005E'->Just[Emph[Str[c,'\x0302']]]-- hat'\x0302'->Just[Emph[Str[c,'\x0302']]]-- hat'~'->Just[Emph[Str[c,'\x0303']]]-- tilde_->NothingexpToInlines_=Nothing