Repository navigation
Expand file tree
/
Copy pathruncode-Makefile.sample
More file actions
97 lines (85 loc) · 3.96 KB
/
Copy pathruncode-Makefile.sample
File metadata and controls
97 lines (85 loc) · 3.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# runcode-Makefile.sample — Part of the runcode package XXX-Date Version-XXX
# Copyright (C) 2020-2026 by Haim Bar and HaiYing Wang
# https://github.com/Ossifragus/runcode
#
# This file may be distributed and/or modified under the conditions of
# the LaTeX Project Public License, either version 1.3c of this license
# or (at your option) any later version.
# The latest version of this license is in http://www.latex-project.org/lppl.txt
#
# Sample Makefile for LaTeX documents that use the runcode package with nohup
# server mode. Copy this file to your project directory as "Makefile", then
# set MAIN and LANGS below to match your document.
#
# Usage:
# make full build: restarts server(s), compiles, caches outputs
# make fast compile only (server must already be running)
# make clean remove auxiliary and generated output files
# make stopserver shut down all talk2stat server(s)
#
# Requirements:
# pip install talk2stat
# Copy wait_for_server.py from the runcode package into this directory.
#
# PIPETIMEOUT note:
# The default PIPETIMEOUT in the generated <LANG>.config is 60 seconds.
# If any script takes longer (e.g. heavy plots, simulations), raise it:
# PIPETIMEOUT = 3600
# Edit the .config file after the first compilation creates it, then run
# "make stopserver" so the fresh server picks up the new value.
##############################################################################
# Configuration — edit these for your project
##############################################################################
MAIN = main # base name of your .tex file (no .tex extension)
LANGS = R # space-separated list of active languages: R python julia matlab
LATEX = pdflatex # or xelatex or lualatex
# Draft-mode flag: skips PDF rendering on the first pass (collects file names
# only). xelatex uses --no-pdf; pdflatex and lualatex use -draftmode.
ifeq ($(LATEX),xelatex)
DRAFT_FLAG = --no-pdf
else
DRAFT_FLAG = -draftmode
endif
# Sync-barrier no-op for each language. The barrier sends a trivial command
# that the server executes in order, guaranteeing all previous scripts have
# finished before the second LaTeX pass begins.
SYNC_CMD_R = invisible(NULL)
SYNC_CMD_python = pass
SYNC_CMD_julia = nothing
SYNC_CMD_matlab = disp('')
##############################################################################
# Targets
##############################################################################
.PHONY: all fast clean stopserver consolidate
all: $(MAIN).pdf
$(MAIN).pdf: $(MAIN).tex
# 1. Stop any existing servers so fresh ones pick up the current .config
$(foreach lang,$(LANGS),\
-python3 -c 'from talk2stat.talk2stat import client; client("./","$(lang)","QUIT")' ;)
# 2. Start fresh servers and wait until each one accepts connections
$(foreach lang,$(LANGS),\
python3 -c 'from talk2stat.talk2stat import server,client; \
server("./","$(lang)") if not client("./","$(lang)","``` ```") \
else print("$(lang) server already running")' ; \
python3 wait_for_server.py $(lang) ;)
# 3. First pass: sends all \run* commands to the server without rendering PDF
$(LATEX) -shell-escape $(DRAFT_FLAG) $(MAIN).tex
# 4. Sync barrier: block until every queued script has finished running
$(foreach lang,$(LANGS),\
python3 -c 'from talk2stat.talk2stat import client; \
client("./","$(lang)","``` $(SYNC_CMD_$(lang)) ```")' ;)
# 5. Final passes: output files exist, so no code is re-executed
$(LATEX) -shell-escape $(MAIN).tex
$(LATEX) -shell-escape $(MAIN).tex
fast:
$(LATEX) -shell-escape $(MAIN).tex
clean:
rm -f $(MAIN).aux $(MAIN).log $(MAIN).out $(MAIN).toc \
$(MAIN).bbl $(MAIN).blg $(MAIN).idx $(MAIN).ind \
generated/*.txt generated/*.md5
stopserver:
$(foreach lang,$(LANGS),\
-python3 -c 'from talk2stat.talk2stat import client; client("./","$(lang)","QUIT")' ;)
rm -f serverPID*.txt *debug.txt talk2stat.log nohup.out
consolidate:
python3 consolidate.py --engine $(LATEX) $(MAIN).tex