main =
   do args <- getArgs -- get the list of command line arguments
      let configFilePath = case args of      
                              [] -> "config"  -- default is ./config
                              xs -> xs !! 0   -- set the config file path
      -- read the IO part of the config:
      [inputDir, texFileName, targetDir, htmlFileName] <- readConfigIO configFilePath
      -- read tex-document contents:
      contents <- readFile (inputDir ++ texFileName)
      let parsed =  parseTex contents    -- parse contents into a list
      let ext = onlyExternalize parsed   -- get a list of the ones to externalize to SVGs
      let numberOfFiles = length ext     -- how many SVGs are there?
      -- read the SVG part of the config:
      [standalone_tex_header, document_commands] <- readConfigSVG configFilePath
      -- write the externalized tex files to the target directory:
      externalize targetDir (texHeader standalone_tex_header parsed) document_commands tex ext
      -- compile the externalized tex files to PDFs:
      mapM_ system (commandList "" ("pdflatex -output-directory " ++ targetDir) tex numberOfFiles)
      -- convert PDFs to SVGs:
      mapM_ system (commandList2 targetDir "pdf2svg" pdf svgTmp numberOfFiles)
      -- read the contents of the generated SVG files:
      svgContents <- mapM readFile (listOfFiles targetDir svgTmp numberOfFiles)
      -- translate the parsed tex file to HTML and write it to the target directory:
      writeFile (targetDir ++ htmlFileName) (toHTML functionDispatch parsed) 
      -- remove SVG styles and enable CSS like styling (still empty):
      multiWrite (listOfFiles targetDir svg numberOfFiles) (map (cssStyleSVG "") svgContents)
      -- remove all files that are not necessary:
      mapM_ removeFile (listOfFiles targetDir tex numberOfFiles)
      mapM_ removeFile (listOfFiles targetDir ".log" numberOfFiles)
      mapM_ removeFile (listOfFiles targetDir ".aux" numberOfFiles)
      mapM_ removeFile (listOfFiles targetDir ".out" numberOfFiles)
      mapM_ removeFile (listOfFiles targetDir svgTmp numberOfFiles)
      mapM_ removeFile (listOfFiles targetDir pdf numberOfFiles)
      

-- suffixes
main =
   do args <- getArgs -- get the list of command line arguments
      let configFilePath = case args of      
                              [] -> "config"  -- default is ./config
                              xs -> xs !! 0   -- set the config file path
      -- read the IO part of the config:
      [inputDir, texFileName, targetDir, htmlFileName] <- readConfigIO configFilePath
      -- read tex-document contents:
      contents <- readFile (inputDir ++ texFileName)
      let parsed =  parseTex contents    -- parse contents into a list
      let ext = onlyExternalize parsed   -- get a list of the ones to externalize to SVGs
      let numberOfFiles = length ext     -- how many SVGs are there?
      -- read the SVG part of the config:
      [standalone_tex_header, document_commands] <- readConfigSVG configFilePath
      -- write the externalized tex files to the target directory:
      externalize targetDir (texHeader standalone_tex_header parsed) document_commands tex ext
      -- compile the externalized tex files to PDFs:
      mapM_ system (commandList "" ("pdflatex -output-directory " ++ targetDir) tex numberOfFiles)
      -- convert PDFs to SVGs:
      mapM_ system (commandList2 targetDir "pdf2svg" pdf svgTmp numberOfFiles)
      -- read the contents of the generated SVG files:
      svgContents <- mapM readFile (listOfFiles targetDir svgTmp numberOfFiles)
      -- translate the parsed tex file to HTML and write it to the target directory:
      writeFile (targetDir ++ htmlFileName) (toHTML functionDispatch parsed) 
      -- remove SVG styles and enable CSS like styling (still empty):
      multiWrite (listOfFiles targetDir svg numberOfFiles) (map (cssStyleSVG "") svgContents)
      -- remove all files that are not necessary:
      mapM_ removeFile (listOfFiles targetDir tex numberOfFiles)
      mapM_ removeFile (listOfFiles targetDir ".log" numberOfFiles)
      mapM_ removeFile (listOfFiles targetDir ".aux" numberOfFiles)
      mapM_ removeFile (listOfFiles targetDir ".out" numberOfFiles)
      mapM_ removeFile (listOfFiles targetDir svgTmp numberOfFiles)
      mapM_ removeFile (listOfFiles targetDir pdf numberOfFiles)
      

-- suffixes
main =
   do args <- getArgs -- get the list of command line arguments
      let configFilePath = case args of      
                              [] -> "config"  -- default is ./config
                              xs -> xs !! 0   -- set the config file path
      -- read the IO part of the config:
      [inputDir, texFileName, targetDir, htmlFileName] <- readConfigIO configFilePath
      -- read tex-document contents:
      contents <- readFile (inputDir ++ texFileName)
      let parsed =  parseTex contents    -- parse contents into a list
      let ext = onlyExternalize parsed   -- get a list of the ones to externalize to SVGs
      let numberOfFiles = length ext     -- how many SVGs are there?
      -- read the SVG part of the config:
      [standalone_tex_header, document_commands] <- readConfigSVG configFilePath
      -- write the externalized tex files to the target directory:
      externalize targetDir (texHeader standalone_tex_header parsed) document_commands tex ext
      -- compile the externalized tex files to PDFs:
      mapM_ system (commandList "" ("pdflatex -output-directory " ++ targetDir) tex numberOfFiles)
      -- convert PDFs to SVGs:
      mapM_ system (commandList2 targetDir "pdf2svg" pdf svgTmp numberOfFiles)
      -- read the contents of the generated SVG files:
      svgContents <- mapM readFile (listOfFiles targetDir svgTmp numberOfFiles)
      -- translate the parsed tex file to HTML and write it to the target directory:
      writeFile (targetDir ++ htmlFileName) (toHTML functionDispatch parsed) 
      -- remove SVG styles and enable CSS like styling (still empty):
      multiWrite (listOfFiles targetDir svg numberOfFiles) (map (cssStyleSVG "") svgContents)
      -- remove all files that are not necessary:
      mapM_ removeFile (listOfFiles targetDir tex numberOfFiles)
      mapM_ removeFile (listOfFiles targetDir ".log" numberOfFiles)
      mapM_ removeFile (listOfFiles targetDir ".aux" numberOfFiles)
      mapM_ removeFile (listOfFiles targetDir ".out" numberOfFiles)
      mapM_ removeFile (listOfFiles targetDir svgTmp numberOfFiles)
      mapM_ removeFile (listOfFiles targetDir pdf numberOfFiles)
      

-- suffixes