mirror of https://github.com/mpastell/Weave.jl
Merge pull request #17 from wildart/tex
fixed latex figure handling, added latex examplepull/21/head
commit
ebcb425f51
|
@ -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}
|
|
@ -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}
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue