{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE NoImplicitPrelude #-}
module Text.Pandoc.Filter.Plot.Renderers.Matlab
( matlab,
matlabSupportedSaveFormats,
)
where
import Text.Pandoc.Filter.Plot.Renderers.Prelude
matlab :: PlotM Renderer
matlab :: PlotM Renderer
matlab = do
Text
cmdargs <- (Configuration -> Text) -> PlotM Text
forall a. (Configuration -> a) -> PlotM a
asksConfig Configuration -> Text
matlabCmdArgs
Renderer -> PlotM Renderer
forall (m :: * -> *) a. Monad m => a -> m a
return (Renderer -> PlotM Renderer) -> Renderer -> PlotM Renderer
forall a b. (a -> b) -> a -> b
$
Renderer :: Toolkit
-> (FigureSpec -> FilePath -> Text)
-> (OutputSpec -> Text)
-> AvailabilityCheck
-> [SaveFormat]
-> [Text -> CheckResult]
-> Text
-> (Text -> Text)
-> FilePath
-> Renderer
Renderer
{ rendererToolkit :: Toolkit
rendererToolkit = Toolkit
Matlab,
rendererCapture :: FigureSpec -> FilePath -> Text
rendererCapture = FigureSpec -> FilePath -> Text
matlabCapture,
rendererCommand :: OutputSpec -> Text
rendererCommand = Text -> OutputSpec -> Text
matlabCommand Text
cmdargs,
rendererAvailability :: AvailabilityCheck
rendererAvailability = AvailabilityCheck
ExecutableExists,
rendererSupportedSaveFormats :: [SaveFormat]
rendererSupportedSaveFormats = [SaveFormat]
matlabSupportedSaveFormats,
rendererChecks :: [Text -> CheckResult]
rendererChecks = [Text -> CheckResult]
forall a. Monoid a => a
mempty,
rendererLanguage :: Text
rendererLanguage = Text
"matlab",
rendererComment :: Text -> Text
rendererComment = Text -> Text -> Text
forall a. Monoid a => a -> a -> a
mappend Text
"% ",
rendererScriptExtension :: FilePath
rendererScriptExtension = FilePath
".m"
}
matlabSupportedSaveFormats :: [SaveFormat]
matlabSupportedSaveFormats :: [SaveFormat]
matlabSupportedSaveFormats = [SaveFormat
PNG, SaveFormat
PDF, SaveFormat
SVG, SaveFormat
JPG, SaveFormat
EPS, SaveFormat
GIF, SaveFormat
TIF]
matlabCommand :: Text -> OutputSpec -> Text
matlabCommand :: Text -> OutputSpec -> Text
matlabCommand Text
cmdargs OutputSpec {FilePath
FigureSpec
Executable
oCWD :: OutputSpec -> FilePath
oExecutable :: OutputSpec -> Executable
oFigurePath :: OutputSpec -> FilePath
oScriptPath :: OutputSpec -> FilePath
oFigureSpec :: OutputSpec -> FigureSpec
oCWD :: FilePath
oExecutable :: Executable
oFigurePath :: FilePath
oScriptPath :: FilePath
oFigureSpec :: FigureSpec
..} =
[st|#{pathToExe oExecutable} #{cmdargs} -sd '#{oCWD}' -noFigureWindows -batch "pandoc_plot_cwd=pwd; run('#{oScriptPath}')"|]
matlabCapture :: FigureSpec -> FilePath -> Script
matlabCapture :: FigureSpec -> FilePath -> Text
matlabCapture = (FigureSpec -> FilePath -> Text) -> FigureSpec -> FilePath -> Text
appendCapture FigureSpec -> FilePath -> Text
matlabCaptureFragment
matlabCaptureFragment :: FigureSpec -> FilePath -> Script
matlabCaptureFragment :: FigureSpec -> FilePath -> Text
matlabCaptureFragment FigureSpec {Bool
Int
FilePath
[FilePath]
[(Text, Text)]
Attr
Text
Renderer
SaveFormat
Executable
blockAttrs :: FigureSpec -> Attr
extraAttrs :: FigureSpec -> [(Text, Text)]
dependencies :: FigureSpec -> [FilePath]
dpi :: FigureSpec -> Int
directory :: FigureSpec -> FilePath
saveFormat :: FigureSpec -> SaveFormat
script :: FigureSpec -> Text
withSource :: FigureSpec -> Bool
caption :: FigureSpec -> Text
fsExecutable :: FigureSpec -> Executable
renderer_ :: FigureSpec -> Renderer
blockAttrs :: Attr
extraAttrs :: [(Text, Text)]
dependencies :: [FilePath]
dpi :: Int
directory :: FilePath
saveFormat :: SaveFormat
script :: Text
withSource :: Bool
caption :: Text
fsExecutable :: Executable
renderer_ :: Renderer
..} FilePath
fname =
[st|
if java.io.File('#{fname}').isAbsolute() > 0
exportpath = '#{fname}';
else
exportpath = fullfile(pandoc_plot_cwd, '#{fname}');
end
if exist("exportgraphics")>0
exportgraphics(gcf, exportpath, 'Resolution', #{dpi});
else
saveas(gcf, exportpath);
end
|]