1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-29 18:43:42 +03:00
juvix/app/Commands/Dev/Scope.hs
Jan Mas Rovira bad61a797f
Export Juvix source code to latex (#2917)
This pr adds two new commands related to latex.
1. `juvix dev latex getJuvixSty`. This command prints the contents of
the `juvix.sty` latex package to stdout. It has no options and the
expected usage is `juvix dev latex getJuvixSty > juvix.sty`.
2. `juvix dev latex export`. Expects a .juvix file as an argument and
outputs to stdout the highlighted module in latex format. Optional flags
`--from LINE`, `--to LINE` to output only the specified line range.
There is a `--mode` flag to choose how you want the output.
   ```
   • standalone: Output a ready to compile LaTeX file
   • wrap: Wrap the code in a Verbatim environment
   • raw: Output only the code (default: standalone)
   ```
4. As shown in the standalone output, one is allowed to choose the theme
when importing the juvix package like this: `\usepackage[theme =
latte]{juvix}`. Available themes are `latte`, `frappe`, `macchiato`,
`mocha`.

Examples:
To generate the following output I ran these commands:
```
cd examples/milestones/HelloWorld
mkdir latex
juvix dev latex getJuvixSty > latex/juvix.sty
juvix dev latex export HelloWorld.juvix > latex/main.tex
cd latex
xelatex main.tex
open main.pdf
```
1. with `\usepackage[theme = latte]{juvix}`:

![image](https://github.com/user-attachments/assets/200c212f-cc18-4dac-95fe-b3828346e7fa)
1. with `\usepackage[theme = frappe]{juvix}`:

![image](https://github.com/user-attachments/assets/a71d07aa-8adc-485c-a41d-3ea62dc2c5a3)
1. with `\usepackage[theme = macchiato]{juvix}`:

![image](https://github.com/user-attachments/assets/e7e878cf-3c2b-4497-a06c-0e8a445b5116)
1. with `\usepackage[theme = mocha]{juvix}`:

![image](https://github.com/user-attachments/assets/79a4c82c-c90e-4844-baf4-f107d8b8ae20)
2024-08-05 11:28:19 +02:00

24 lines
952 B
Haskell

module Commands.Dev.Scope where
import Commands.Base
import Commands.Dev.Scope.Options
import Juvix.Compiler.Concrete.Language
import Juvix.Compiler.Concrete.Print qualified as Print
import Juvix.Compiler.Concrete.Translation.FromParsed.Analysis.Scoping qualified as Scoper
runCommand :: (Members AppEffects r) => ScopeOptions -> Sem r ()
runCommand opts = do
globalOpts <- askGlobalOptions
res :: Scoper.ScoperResult <- runPipelineNoOptions (opts ^. scopeInputFile) upToScopingEntry
let m :: Module 'Scoped 'ModuleTop = res ^. Scoper.resultModule
if
| opts ^. scopeWithComments ->
renderStdOut (Print.ppOut (globalOpts, opts) (Scoper.getScoperResultComments res) m)
| otherwise ->
renderStdOut (Print.ppOutNoComments (globalOpts, opts) m)
when (opts ^. scopeListComments) $ do
newline
newline
renderStdOutLn @Text "Comments:"
renderStdOutLn (prettyText (Scoper.getScoperResultComments res))