Merge pull request #17 from wildart/tex

fixed latex figure handling, added latex example
pull/21/head
Matti Pastell 2014-12-08 19:27:54 +02:00
commit ebcb425f51
3 changed files with 71 additions and 21 deletions

11
examples/Jweave.sty Normal file
View File

@ -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}

43
examples/julia_latex.texw Normal file
View File

@ -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}
<<term=true>>=
x = 1:10
d = {"Weave" => "testing"}
y = [2, 4 ,8]
@
\section*{Capturing figures}
The figures and code can be included in the output.
<<fig_cap="sin(x) function."; label="sin_fun"; fig_pos="ht">>=
using Gadfly
x = linspace(0, 2π, 200)
plot(x=x, y = sin(x), Geom.line)
@
<<echo=false; fig_cap="cos(x) function.">>=
plot(x=x, y = cos(x), Geom.line)
@
<<echo=false; label="cos2_fun">>=
plot(x=x, y = cos(2x), Geom.line)
@
\end{document}

View File

@ -44,8 +44,6 @@ end
function format_codechunk(chunk, formatdict) function format_codechunk(chunk, formatdict)
if haskey(formatdict, :indent) if haskey(formatdict, :indent)
chunk[:content] = indent(chunk[:content], formatdict[:indent]) chunk[:content] = indent(chunk[:content], formatdict[:indent])
end end
@ -91,17 +89,15 @@ function format_codechunk(chunk, formatdict)
end end
function format_termchunk(chunk, formatdict) function format_termchunk(chunk, formatdict)
if chunk[:echo] && chunk[:results] != "hidden" if chunk[:echo] && chunk[:results] != "hidden"
result = "$(formatdict[:termstart])$(chunk[:result])\n" result = "$(formatdict[:termstart])$(chunk[:result])\n"
#@show chunk[:term_state] #@show chunk[:term_state]
chunk[:term_state] == :text && (result*= "$(formatdict[:termend])\n") chunk[:term_state] == :text && (result*= "$(formatdict[:termend])\n")
else else
result = "" result = ""
end end
return result return result
end end
function indent(text, nindent) function indent(text, nindent)
@ -205,7 +201,7 @@ function formatfigures(chunk, docformat::Tex)
figstring = "" figstring = ""
if f_env != nothing if f_env != nothing
result *= """\\begin{$f_env}\n""" result *= """\\begin{$f_env}[$f_pos]\n"""
end end
@ -215,21 +211,21 @@ function formatfigures(chunk, docformat::Tex)
# Figure environment # Figure environment
if caption != nothing if caption != nothing
result *= string("\\begin{figure}[$f_pos]\n", result *= string("\\center\n",
"\\center\n",
"$figstring", "$figstring",
"\\caption{$caption}\n") "\\caption{$caption}\n")
if chunk[:name] != nothing
label = chunk[:name]
result *= "\label{fig:$label}\n"
result *= "\\end{figure}\n"
end
else else
result *= figstring result *= figstring
end end
if chunk[:name] != nothing
label = chunk[:name]
result *= "\\label{fig:$label}\n"
end
if f_env != nothing if f_env != nothing
result += "\\end{$f_env}\n" result *= "\\end{$f_env}\n"
end end
return result return result