{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE RecordWildCards #-}
module Text.Pandoc.Filter.Plot.Renderers.Matlab (
matlabSupportedSaveFormats
, matlabCommand
, matlabCapture
, matlabAvailable
) where
import System.Directory (exeExtension)
import Text.Pandoc.Filter.Plot.Renderers.Prelude
matlabSupportedSaveFormats :: [SaveFormat]
matlabSupportedSaveFormats = [PNG, PDF, SVG, JPG, EPS, GIF, TIF]
matlabCommand :: OutputSpec -> Text -> Text
matlabCommand OutputSpec{..} exe = [st|#{exe} -batch "run('#{oScriptPath}')"|]
matlabAvailable :: PlotM Bool
matlabAvailable = asksConfig matlabExe >>= (\exe -> liftIO $ existsOnPath (exe <> exeExtension))
matlabCapture :: FigureSpec -> FilePath -> Script
matlabCapture = appendCapture matlabCaptureFragment
matlabCaptureFragment :: FigureSpec -> FilePath -> Script
matlabCaptureFragment FigureSpec{..} fname = [st|
if exist("exportgraphics")>0
exportgraphics(gcf, '#{fname}', 'Resolution', #{dpi});
else
saveas(gcf, '#{fname}');
end
|]