Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore hidden #37

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/Katla/Engine.idr
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,12 @@ engineWithRange input output lineNumberWidth meta driver rowRange currentDecor c
engineWithRange input output lineNumberWidth meta driver rowRange nextDecor nextPos

export
codeTeX : LiterateStyle
codeTeX = MkLitStyle
[(#"\begin{code}"#, #"\end{code}"#)]
Nil
[".tex", ".ltx"]
export
engine : Backend
-> Config
-> (input, output : File)
Expand All @@ -262,7 +268,7 @@ engine Literate cfg input output lnw meta driver pos
= do Right content <- fRead input
| Left err => do putStrLn "Error: \{show err}"
exitFailure
let Right ts = lexLiterate styleTeX content
let Right ts = lexLiterate codeTeX content
| Left err => do putStrLn "Error: \{show err}"
exitFailure
initSty cfg
Expand Down
165 changes: 84 additions & 81 deletions src/Katla/LaTeX.idr
Original file line number Diff line number Diff line change
Expand Up @@ -29,123 +29,126 @@ annotate (Just dec) s = apply (convert dec) s
where

apply : String -> String -> String
apply f a = "\\\{f}{\{a}}"
apply f a = #"\\#{f}{\#{a}}"#

export
laTeXHeader : Config -> String
laTeXHeader cfg = """
\\usepackage{fancyvrb}
\\usepackage[x11names]{xcolor}
\\newcommand{\\Katla} [2][]{\\VerbatimInput[commandchars=\\\\\\{\\}#1]{#2}}
\\newcommand{\\KatlaNewline} {}
\\newcommand{\\KatlaSpace} {\{cfg.space}}
\\newcommand{\\KatlaDash} {\\string-}
\\newcommand{\\KatlaUnderscore} {\\string_}
\\newcommand{\\KatlaTilde} {\\string~}
\\newcommand{\\IdrisHlightFont} {\{cfg.font}}
\\newcommand{\\IdrisHlightStyleData} {\{cfg.datacons .style}}
\\newcommand{\\IdrisHlightStyleType} {\{cfg.typecons .style}}
\\newcommand{\\IdrisHlightStyleBound} {\{cfg.bound .style}}
\\newcommand{\\IdrisHlightStyleFunction}{\{cfg.function .style}}
\\newcommand{\\IdrisHlightStyleKeyword} {\{cfg.keyword .style}}
\\newcommand{\\IdrisHlightStyleImplicit}{\{cfg.bound .style}}
\\newcommand{\\IdrisHlightStyleComment} {\{cfg.comment .style}}
\\newcommand{\\IdrisHlightStyleHole} {\{cfg.hole .style}}
\\newcommand{\\IdrisHlightStyleNamespace}{\{cfg.namespce.style}}
\\newcommand{\\IdrisHlightStylePostulate}{\{cfg.postulte.style}}
\\newcommand{\\IdrisHlightStyleModule} {\{cfg.aModule .style}}

\\newcommand{\\IdrisHlightColourData} {\{cfg.datacons .colour}}
\\newcommand{\\IdrisHlightColourType} {\{cfg.typecons .colour}}
\\newcommand{\\IdrisHlightColourBound} {\{cfg.bound .colour}}
\\newcommand{\\IdrisHlightColourFunction}{\{cfg.function .colour}}
\\newcommand{\\IdrisHlightColourKeyword} {\{cfg.keyword .colour}}
\\newcommand{\\IdrisHlightColourImplicit}{\{cfg.bound .colour}}
\\newcommand{\\IdrisHlightColourComment} {\{cfg.comment .colour}}
\\newcommand{\\IdrisHlightColourHole} {\{cfg.hole .colour}}
\\newcommand{\\IdrisHlightColourNamespace}{\{cfg.namespce.colour}}
\\newcommand{\\IdrisHlightColourPostulate}{\{cfg.postulte.colour}}
\\newcommand{\\IdrisHlightColourModule} {\{cfg.aModule .colour}}

\\newcommand{\\IdrisHole}[1]{{%
\\colorbox{\\IdrisHlightColourHole}{%
\\IdrisHlightStyleHole\\IdrisHlightFont%
laTeXHeader cfg = #"""
\usepackage{fancyvrb}
\usepackage[x11names]{xcolor}
\newcommand{\Katla} [2][]{\VerbatimInput[commandchars=\\\{\}#1]{#2}}
\newcommand{\KatlaNewline} {}
\newcommand{\KatlaSpace} {\#{cfg.space}}
\newcommand{\KatlaDash} {\string-}
\newcommand{\KatlaUnderscore} {\string_}
\newcommand{\KatlaTilde} {\string~}
\newcommand{\IdrisHlightFont} {\#{cfg.font}}
\newcommand{\IdrisHlightStyleData} {\#{cfg.datacons .style}}
\newcommand{\IdrisHlightStyleType} {\#{cfg.typecons .style}}
\newcommand{\IdrisHlightStyleBound} {\#{cfg.bound .style}}
\newcommand{\IdrisHlightStyleFunction}{\#{cfg.function .style}}
\newcommand{\IdrisHlightStyleKeyword} {\#{cfg.keyword .style}}
\newcommand{\IdrisHlightStyleImplicit}{\#{cfg.bound .style}}
\newcommand{\IdrisHlightStyleComment} {\#{cfg.comment .style}}
\newcommand{\IdrisHlightStyleHole} {\#{cfg.hole .style}}
\newcommand{\IdrisHlightStyleNamespace}{\{cfg.namespce.style}}
\newcommand{\IdrisHlightStylePostulate}{\{cfg.postulte.style}}
\newcommand{\IdrisHlightStyleModule} {\{cfg.aModule .style}}

\newcommand{\IdrisHlightColourData} {\#{cfg.datacons .colour}}
\newcommand{\IdrisHlightColourType} {\#{cfg.typecons .colour}}
\newcommand{\IdrisHlightColourBound} {\#{cfg.bound .colour}}
\newcommand{\IdrisHlightColourFunction}{\#{cfg.function .colour}}
\newcommand{\IdrisHlightColourKeyword} {\#{cfg.keyword .colour}}
\newcommand{\IdrisHlightColourImplicit}{\#{cfg.bound .colour}}
\newcommand{\IdrisHlightColourComment} {\#{cfg.comment .colour}}
\newcommand{\IdrisHlightColourHole} {\#{cfg.hole .colour}}
\newcommand{\IdrisHlightColourNamespace}{\#{cfg.namespce.colour}}
\newcommand{\IdrisHlightColourPostulate}{\#{cfg.postulte.colour}}
\newcommand{\IdrisHlightColourModule} {\#{cfg.aModule .colour}}

\newcommand{\IdrisHole}[1]{{%
\colorbox{\IdrisHlightColourHole}{%
\IdrisHlightStyleHole\IdrisHlightFont%
#1}}}

\\newcommand{\\RawIdrisHighlight}[3]{{\\textcolor{#1}{\\IdrisHlightFont#2{#3}}}}
\newcommand{\RawIdrisHighlight}[3]{{\textcolor{#1}{\IdrisHlightFont#2{#3}}}}

\\newcommand{\\IdrisData}[1]{\\RawIdrisHighlight{\\IdrisHlightColourData}{\\IdrisHlightStyleData}{#1}}
\\newcommand{\\IdrisType}[1]{\\RawIdrisHighlight{\\IdrisHlightColourType}{\\IdrisHlightStyleType}{#1}}
\\newcommand{\\IdrisBound}[1]{\\RawIdrisHighlight{\\IdrisHlightColourBound}{\\IdrisHlightStyleBound}{#1}}
\\newcommand{\\IdrisFunction}[1]{\\RawIdrisHighlight{\\IdrisHlightColourFunction}{\\IdrisHlightStyleFunction}{#1}}
\\newcommand{\\IdrisKeyword}[1]{\\RawIdrisHighlight{\\IdrisHlightColourKeyword}{\\IdrisHlightStyleKeyword}{#1}}
\\newcommand{\\IdrisImplicit}[1]{\\RawIdrisHighlight{\\IdrisHlightColourImplicit}{\\IdrisHlightStyleImplicit}{#1}}
\\newcommand{\\IdrisComment}[1]{\\RawIdrisHighlight{\\IdrisHlightColourComment}{\\IdrisHlightStyleComment}{#1}}
\\newcommand{\\IdrisNamespace}[1]{\\RawIdrisHighlight{\\IdrisHlightColourNamespace}{\\IdrisHlightStyleNamespace}{#1}}
\\newcommand{\\IdrisPostulate}[1]{\\RawIdrisHighlight{\\IdrisHlightColourPostulate}{\\IdrisHlightStylePostulate}{#1}}
\\newcommand{\\IdrisModule}[1]{\\RawIdrisHighlight{\\IdrisHlightColourModule}{\\IdrisHlightStyleModule}{#1}}
\newcommand{\IdrisData}[1]{\RawIdrisHighlight{\IdrisHlightColourData}{\IdrisHlightStyleData}{#1}}
\newcommand{\IdrisType}[1]{\RawIdrisHighlight{\IdrisHlightColourType}{\IdrisHlightStyleType}{#1}}
\newcommand{\IdrisBound}[1]{\RawIdrisHighlight{\IdrisHlightColourBound}{\IdrisHlightStyleBound}{#1}}
\newcommand{\IdrisFunction}[1]{\RawIdrisHighlight{\IdrisHlightColourFunction}{\IdrisHlightStyleFunction}{#1}}
\newcommand{\IdrisKeyword}[1]{\RawIdrisHighlight{\IdrisHlightColourKeyword}{\IdrisHlightStyleKeyword}{#1}}
\newcommand{\IdrisImplicit}[1]{\RawIdrisHighlight{\IdrisHlightColourImplicit}{\IdrisHlightStyleImplicit}{#1}}
\newcommand{\IdrisComment}[1]{\RawIdrisHighlight{\IdrisHlightColourComment}{\IdrisHlightStyleComment}{#1}}
\newcommand{\IdrisNamespace}[1]{\RawIdrisHighlight{\IdrisHlightColourNamespace}{\IdrisHlightStyleNamespace}{#1}}
\newcommand{\IdrisPostulate}[1]{\RawIdrisHighlight{\IdrisHlightColourPostulate}{\IdrisHlightStylePostulate}{#1}}
\newcommand{\IdrisModule}[1]{\RawIdrisHighlight{\IdrisHlightColourModule}{\IdrisHlightStyleModule}{#1}}

\\DefineVerbatimEnvironment%
{code}{Verbatim}{commandchars=\\\\\\{\\}}
\DefineVerbatimEnvironment%
{code}{Verbatim}{commandchars=\\\{\}}

\usepackage{comment}
\excludecomment{hidden}

% Bugfix in fancyvrb to allow inline saved listings
\\makeatletter
\\let\\FV@ProcessLine\\relax
\\makeatother
\makeatletter
\let\FV@ProcessLine\relax
\makeatother

"""
"""#


export
standalonePre : Config -> String
standalonePre config = """
\\documentclass{article}
standalonePre config = #"""
\documentclass{article}

\\usepackage{inconsolata}
\usepackage{inconsolata}

\{laTeXHeader config}
\#{laTeXHeader config}

\\begin{document}
\\begin{Verbatim}[commandchars=\\\\\\{\\}]
"""
\begin{document}
\begin{Verbatim}[commandchars=\\\{\}]
"""#

export
standalonePost : String
standalonePost = """
\\end{Verbatim}
\\end{document}
"""
standalonePost = #"""
\end{Verbatim}
\end{document}
"""#

export
makeMacroPre : String -> String
makeMacroPre name = """
\\newcommand\\\{name}[1][]{\\UseVerbatim[#1]{\{name}}}
\\begin{SaveVerbatim}[commandchars=\\\\\\{\\}]{\{name}}
"""
makeMacroPre name = #"""
\newcommand\\#{name}[1][]{\UseVerbatim[#1]{\#{name}}}
\begin{SaveVerbatim}[commandchars=\\\{\}]{\#{name}}
"""#

export
makeMacroPost : String
makeMacroPost = """
\\end{SaveVerbatim}
"""
makeMacroPost = #"""
\end{SaveVerbatim}
"""#

export
makeInlineMacroPre : String -> String
makeInlineMacroPre name = """
\\newcommand\\\{name}[1][]{\\UseVerb[#1]{\{name}}}
\\begin{SaveVerbatim}[commandchars=\\\\\\{\\}]{\{name}}
"""
makeInlineMacroPre name = #"""
\newcommand\\#{name}[1][]{\UseVerb[#1]{\#{name}}}
\begin{SaveVerbatim}[commandchars=\\\{\}]{\#{name}}
"""#

export
makeInlineMacroPost : String
makeInlineMacroPost = """
\\end{SaveVerbatim}
"""
makeInlineMacroPost = #"""
\end{SaveVerbatim}
"""#

export
mkDriver : Config -> Driver
mkDriver config = MkDriver
(\_, _ => "", "\\KatlaNewline{}")
(\_, _ => "", #"\KatlaNewline{}"#)
escapeLatex
annotate
(standalonePre config, standalonePost)
Expand Down
14 changes: 7 additions & 7 deletions src/Katla/Literate.idr
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ initStyFile = do

export
makeMacroPre : String -> String
makeMacroPre name = """
\\begin{code}
"""
makeMacroPre name = #"""
\begin{code}
"""#

export
makeMacroPost : String
makeMacroPost = """
\\end{code}
"""
makeMacroPost = #"""
\end{code}
"""#

export
mkDriver : Config -> Driver
mkDriver config = MkDriver
(\ wdth, ln => "", "\\KatlaNewline{}")
(\ wdth, ln => "", #"\KatlaNewline{}"#)
(escapeLatex)
annotate
("", "")
Expand Down
3 changes: 3 additions & 0 deletions tests/examples/config/expected
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
\DefineVerbatimEnvironment%
{code}{Verbatim}{commandchars=\\\{\}}

\usepackage{comment}
\excludecomment{hidden}

% Bugfix in fancyvrb to allow inline saved listings
\makeatletter
\let\FV@ProcessLine\relax
Expand Down
3 changes: 3 additions & 0 deletions tests/examples/init/expected
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@
\DefineVerbatimEnvironment%
{code}{Verbatim}{commandchars=\\\{\}}

\usepackage{comment}
\excludecomment{hidden}

% Bugfix in fancyvrb to allow inline saved listings
\makeatletter
\let\FV@ProcessLine\relax
Expand Down
5 changes: 5 additions & 0 deletions tests/examples/literate/Source.tex
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ \section{My cool paper}
main = putStrLn "Hello from inside TeX"
\end{code}

\begin{hidden}
succ : Nat -> Nat
succ = S
\end{hidden}

We're hoping the output pdf will have the \textbf{code blocks} highlighted
while the rest is typeset by \LaTeX{}.

Expand Down
3 changes: 3 additions & 0 deletions tests/examples/literate/idris2-expected.sty
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
\DefineVerbatimEnvironment%
{code}{Verbatim}{commandchars=\\\{\}}

\usepackage{comment}
\excludecomment{hidden}

% Bugfix in fancyvrb to allow inline saved listings
\makeatletter
\let\FV@ProcessLine\relax
Expand Down
5 changes: 5 additions & 0 deletions tests/examples/literate/source-expected.tex
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ \section{My cool paper}
\IdrisFunction{main}\KatlaSpace{}\IdrisKeyword{=}\KatlaSpace{}\IdrisFunction{putStrLn}\KatlaSpace{}\IdrisData{"Hello\KatlaSpace{}from\KatlaSpace{}inside\KatlaSpace{}TeX"}\KatlaNewline{}
\end{code}

\begin{hidden}
succ : Nat -> Nat
succ = S
\end{hidden}

We're hoping the output pdf will have the \textbf{code blocks} highlighted
while the rest is typeset by \LaTeX{}.

Expand Down
3 changes: 3 additions & 0 deletions tests/examples/macros/expected
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
\DefineVerbatimEnvironment%
{code}{Verbatim}{commandchars=\\\{\}}

\usepackage{comment}
\excludecomment{hidden}

% Bugfix in fancyvrb to allow inline saved listings
\makeatletter
\let\FV@ProcessLine\relax
Expand Down
3 changes: 3 additions & 0 deletions tests/examples/preamble/expected
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
\DefineVerbatimEnvironment%
{code}{Verbatim}{commandchars=\\\{\}}

\usepackage{comment}
\excludecomment{hidden}

% Bugfix in fancyvrb to allow inline saved listings
\makeatletter
\let\FV@ProcessLine\relax
Expand Down
3 changes: 3 additions & 0 deletions tests/examples/standalone/expected
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
\DefineVerbatimEnvironment%
{code}{Verbatim}{commandchars=\\\{\}}

\usepackage{comment}
\excludecomment{hidden}

% Bugfix in fancyvrb to allow inline saved listings
\makeatletter
\let\FV@ProcessLine\relax
Expand Down
Loading