I know this is an old question which hasn't seen any activity in quite a while. This topic is close to my heart as I've used many Latin texts during my studies at university.
As a philosopher and historian I've often used translations of ancient texts and I always wondered how to typeset them. I can only imagine the nightmare this task must be, if one were to use a regular word processor.
Since I am sure that this is a topic/problem many in the classical studies part of the humanities are faced with, I would like to give a minimal example illustrating the wonderful possibilities of the reledmac
and reledpar
package.
\documentclass[a6paper,11pt]{scrbook}
\usepackage{libertine}
\usepackage{fontspec}
\usepackage[latin,english]{babel}
\usepackage[series={},nocritical,noend,noeledsec,nofamiliar,noledgroup]{reledmac}
\usepackage{reledpar}
\begin{document}
\date{\today}
\title{Setting Parallel Texts with reledpar}
\author{A. U. Thor}
\maketitle
\begin{pages}
\begin{Leftside}
\beginnumbering
\pstart
\begin{otherlanguage}{latin}
quo usque tandem abutere, Catilina, patientia
nostra? quam diu etiam furor iste tuus nos eludet? quem ad finem sese effrenata
iactabit audacia? nihilne te nocturnum praesidium Palati\footnote{The Palatine Hill,
(/ˈpælətaɪn/; Latin: Collis Palatium or Mons Palatinus; Italian: Palatino [palaˈtiːno])
which is the centremost of the Seven Hills of Rome, is one of the most ancient
parts of the city and has been called “the first nucleus of the Roman Empire.”},
nihil urbis vigiliae, nihil timor populi, nihil concursus bonorum omnium,
nihil hic munitissimus habendi senatus locus, nihil horum ora voltusque moverunt?
patere tua consilia non sentis, constrictam iam horum omnium scientia teneri
coniurationem tuam non vides? quid proxima, quid superiore nocte egeris,
ubi fueris, quos convocaveris, quid consili ceperis quem nostrum ignorare arbitraris?
\end{otherlanguage}
\pend
\pstart
\begin{otherlanguage}{latin}
O tempora, o mores!
\end{otherlanguage}
\pend
\endnumbering
\end{Leftside}
\begin{Rightside}
\beginnumbering
\pstart
When, O Catiline, do you mean to cease
abusing our patience? How long is that madness of yours still to mock us? When
is there to be an end of that unbridled audacity of yours, swaggering about as
it does now? Do not the nightly guards placed on the Palatine Hill — do not the
watches posted throughout the city — does not the alarm of the people, and the
union of all good men — does not the precaution taken of assembling the senate
in this most defensible place — do not the looks and countenances of this
venerable body here present, have any effect upon you? Do you not feel that your
plans are detected? Do you not see that your conspiracy is already arrested and
rendered powerless by the knowledge which every one here possesses of it? What
is there that you did last night, what the night before — where is it that you
were — who was there that you summoned to meet you — what design was there which
was adopted by you, with which you think that any one of us is unacquainted?
\pend
\pstart
Shame on the age and on its principles!
\pend
\endnumbering
\end{Rightside}
\end{pages}
\Pages
\end{document}
This is what you get:
- proper alignment of paragraphs
- footnotes
- different font sizes are no problem
And this is what it looks like:
The best way to do this is to make your external file into a module. That means, you make sure that all variables are local
and in the end you return a table which exports all user-accessible functions. For example f(x,y,z)
is not going to be used outside, so I won't export it. As you can see I can also export functions under a different name.
-- Differential equation of the Lorenz attractor
local function f(x,y,z)
local sigma = 3
local rho = 26.5
local beta = 1
return {sigma*(y-x), -x*z + rho*x - y, x*y - beta*z}
end
-- Code to write PGFplots data as coordinates
local function print_LorAttrWithEulerMethod(h,npoints,option)
-- The initial point (x0,y0,z0)
local x0 = 0.0
local y0 = 1.0
local z0 = 0.0
-- we add a random number between -0.25 and 0.25
local x = x0 + (math.random()-0.5)/2
local y = y0 + (math.random()-0.5)/2
local z = z0 + (math.random()-0.5)/2
if option~=[[]] then
tex.sprint("\\addplot3["..option.."] coordinates{")
else
tex.sprint("\\addplot3 coordinates{")
end
-- we dismiss the first 100 points to go into the attractor
for i=1, 100 do
local m = f(x,y,z)
x = x + h * m[1]
y = y + h * m[2]
z = z + h * m[3]
end
for i=1, npoints do
local m = f(x,y,z)
x = x + h * m[1]
y = y + h * m[2]
z = z + h * m[3]
tex.sprint("("..x..","..y..","..z..")")
end
tex.sprint("}")
end
return { LorenzAttractor = print_LorAttrWithEulerMethod }
An advantage of having the Lua code in a separate file is that you do not have to worry about catcodes. Therefore you don't need the luacode
package at all. The module you created in scrap.lua
can be loaded like any regular Lua module. Usually you would load it like
local scrap = require("scrap")
but that won't work in LuaTeX because the scrap
variable would only be local to the \directlua
chunk it is mentioned in and can hence not be used in other chunks. Therefore you have to make a global variable scrap
to encapsulate the module
\directlua{scrap = require("scrap")}
The full document would read
\documentclass{article}
\usepackage{pgfplots}
\usepackage{tikz}
\directlua{scrap = require("scrap")}
\newcommand\addLUADEDplot[3][]{%
\directlua{scrap.LorenzAttractor(#2,#3,[[#1]])}%
}
\begin{document}
\begin{tikzpicture}
\begin{axis}
% SYNTAX: Solution of the Lorenz system
% with step h=0.02 sampled at 1000 points.
\addLUADEDplot[color=red,smooth]{0.02}{1000};
\addLUADEDplot[color=green,smooth]{0.02}{1000};
\addLUADEDplot[color=blue,smooth]{0.02}{1000};
\addLUADEDplot[color=cyan,smooth]{0.02}{1000};
\addLUADEDplot[color=magenta,smooth]{0.02}{1000};
\addLUADEDplot[color=yellow,smooth]{0.02}{1000};
\end{axis}
\end{tikzpicture}
\end{document}
Best Answer
The
luacode*
environment forms a group, in common with other LaTeX environments. Thus if you want to use this approach and have the value 'escape' then you will need to use\gdef
As observed in Which Lua environment should I use with LuaTeX (LuaLaTeX)?, the best plan is to use a separate file and load it without grouping, etc.