{-# LANGUAGE OverloadedStrings #-}moduleText.LaTeX.Base.Warnings(-- * Warnings datatypeWarning(..),TeXCheck,check,checkFromFunction-- * Several checkings,checkLabels,checkClass,checkDoc-- * Complete checking,checkAll)whereimportText.LaTeX.Base.SyntaximportControl.Monad.StateimportData.TextimportData.MaybeimportControl.ArrowimportData.Monoid-- | List of possible warnings.dataWarning=UnusedLabelText-- ^ There is an unused label. Argument is its name.|UndefinedLabelText-- ^ There is a reference to an undefined label. Arguments is the name.--|NoClassSelected-- ^ No class selected with 'documentclass'.|NoDocumentInserted-- ^ No 'document' inserted.--|CustomWarningText-- ^ Custom warning for custom checkings. Use it as you want.deriving(Eq,Show)-- | A 'TeXCheck' is a function that checks possible warnings from a 'LaTeX' value.-- Use the 'Monoid' instance to combine check functions.newtypeTeXCheck=TC{check::LaTeX->[Warning]-- ^ Apply a checking.}-- | Build a 'TeXCheck' from a function.checkFromFunction::(LaTeX->[Warning])->TeXCheckcheckFromFunction=TCinstanceMonoidTeXCheckwheremempty=TC$const[]mappend(TCtc1)(TCtc2)=TC$uncurrymappend.(tc1&&&tc2)checkAll::TeXCheckcheckAll=mconcat[checkLabels,checkClass,checkDoc]-- Searching for 'documentclass' and 'document'typeBoolSt=StateBool-- | Check if a document class is specified for the document (using 'documentclass').checkClass::TeXCheckcheckClass=TC$\l->ifexecState(classcheckl)Falsethen[]else[NoClassSelected]classcheck::LaTeX->BoolSt()classcheck(TeXCommc_)=casecof"documentclass"->putTrue_->return()classcheck(TeXBracesl)=classchecklclasscheck(TeXSeql1l2)=classcheckl1>>classcheckl2classcheck_=return()-- | Check if the 'document' environment is called in a 'LaTeX'.checkDoc::TeXCheckcheckDoc=TC$\l->ifexecState(doccheckl)Falsethen[]else[NoDocumentInserted]doccheck::LaTeX->BoolSt()doccheck(TeXEnvn__)=casenof"document"->putTrue_->return()doccheck(TeXBracesl)=doccheckldoccheck(TeXSeql1l2)=doccheckl1>>doccheckl2doccheck_=return()-- Checking labelsdataLabWarn=RefNoLabelText|LabelNoRefText|LabelRefTextlabWarnToWarning::LabWarn->MaybeWarninglabWarnToWarning(RefNoLabeln)=Just$UndefinedLabelnlabWarnToWarning(LabelNoRefn)=Just$UnusedLabelnlabWarnToWarning_=NothingtypeLabSt=State[LabWarn]-- | Checking for unused labels or references tu undefined labels.checkLabels::TeXCheckcheckLabels=TC$\l->catMaybes.fmaplabWarnToWarning$execState(labcheckl)[]labcheck::LaTeX->LabSt()labcheck(TeXCommc[FixArg(TeXRawn)])=casecof"label"->newlabn"ref"->newrefn"pageref"->newrefnlabcheck(TeXEnv__l)=labcheckllabcheck(TeXMathl)=labcheckllabcheck(TeXOp_l1l2)=labcheckl1>>labcheckl2labcheck(TeXBracesl)=labcheckllabcheck(TeXSeql1l2)=labcheckl1>>labcheckl2labcheck_=return()newlab::Text->LabSt()newlabn=dost<-getletaddLab::Text->[LabWarn]->[LabWarn]addLabn[]=[LabelNoRefn]addLabnl@(x:xs)=letys=x:addLabnxsincasexofRefNoLabelm->ifn==mthenLabelRefn:xselseysLabelNoRefm->ifn==mthenlelseysLabelRefm->ifn==mthenlelseysput$addLabnstnewref::Text->LabSt()newrefn=dost<-getletaddRef::Text->[LabWarn]->[LabWarn]addRefn[]=[RefNoLabeln]addRefnl@(x:xs)=letys=x:addRefnxsincasexofRefNoLabelm->ifn==mthenlelseysLabelNoRefm->ifn==mthenLabelRefn:xselseysLabelRefm->ifn==mthenlelseysput$addRefnst