diff --git a/examples/Jweave.sty b/examples/Jweave.sty new file mode 100644 index 0000000..af4c17f --- /dev/null +++ b/examples/Jweave.sty @@ -0,0 +1,11 @@ +\NeedsTeXFormat{LaTeX2e} +\ProvidesPackage{Jweave}{} + +\RequirePackage[utf8]{inputenc} +\RequirePackage{textgreek} +\RequirePackage{graphicx} +\RequirePackage{fancyvrb,textcomp} + +\DefineVerbatimEnvironment{juliain}{Verbatim}{fontshape=sl} +\DefineVerbatimEnvironment{juliaout}{Verbatim}{} +\DefineVerbatimEnvironment{juliacode}{Verbatim}{fontshape=sl} \ No newline at end of file diff --git a/examples/julia_latex.texw b/examples/julia_latex.texw new file mode 100644 index 0000000..9597a6c --- /dev/null +++ b/examples/julia_latex.texw @@ -0,0 +1,43 @@ +\documentclass[12pt]{article} +\usepackage{hyperref} +\usepackage{Jweave} % Required to convert custom envs: juliacode & juliaout + +\title{Introduction to Julia Weave} + +\begin{document} +\maketitle + +This a sample \href{http://julialang.org/}{Julia} latex document that can +be executed using Weave. Output from code chunks and Gadfly +plots will be included in the weaved document. + +This documented can be turned into Latex document with captured +result from Julia prompt. + +\section*{Terminal chunk} +<>= +x = 1:10 +d = {"Weave" => "testing"} +y = [2, 4 ,8] +@ + +\section*{Capturing figures} + +The figures and code can be included in the output. + +<>= +using Gadfly +x = linspace(0, 2π, 200) +plot(x=x, y = sin(x), Geom.line) +@ + +<>= +plot(x=x, y = cos(x), Geom.line) +@ + +<>= +plot(x=x, y = cos(2x), Geom.line) +@ + + +\end{document} \ No newline at end of file diff --git a/src/formatters.jl b/src/formatters.jl index 0ab0d3a..809ea0f 100644 --- a/src/formatters.jl +++ b/src/formatters.jl @@ -44,8 +44,6 @@ end function format_codechunk(chunk, formatdict) - - if haskey(formatdict, :indent) chunk[:content] = indent(chunk[:content], formatdict[:indent]) end @@ -91,17 +89,15 @@ function format_codechunk(chunk, formatdict) end - - function format_termchunk(chunk, formatdict) - if chunk[:echo] && chunk[:results] != "hidden" - result = "$(formatdict[:termstart])$(chunk[:result])\n" - #@show chunk[:term_state] - chunk[:term_state] == :text && (result*= "$(formatdict[:termend])\n") - else - result = "" - end -return result + if chunk[:echo] && chunk[:results] != "hidden" + result = "$(formatdict[:termstart])$(chunk[:result])\n" + #@show chunk[:term_state] + chunk[:term_state] == :text && (result*= "$(formatdict[:termend])\n") + else + result = "" + end + return result end function indent(text, nindent) @@ -205,7 +201,7 @@ function formatfigures(chunk, docformat::Tex) figstring = "" if f_env != nothing - result *= """\\begin{$f_env}\n""" + result *= """\\begin{$f_env}[$f_pos]\n""" end @@ -215,21 +211,21 @@ function formatfigures(chunk, docformat::Tex) # Figure environment if caption != nothing - result *= string("\\begin{figure}[$f_pos]\n", - "\\center\n", + result *= string("\\center\n", "$figstring", "\\caption{$caption}\n") - if chunk[:name] != nothing - label = chunk[:name] - result *= "\label{fig:$label}\n" - result *= "\\end{figure}\n" - end else result *= figstring end + if chunk[:name] != nothing + label = chunk[:name] + result *= "\\label{fig:$label}\n" + end + + if f_env != nothing - result += "\\end{$f_env}\n" + result *= "\\end{$f_env}\n" end return result