File: add-style.lua

package info (click to toggle)
ipe 7.2.23%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 4,784 kB
  • sloc: cpp: 42,224; makefile: 634; ansic: 46; sh: 45; xml: 17
file content (35 lines) | stat: -rw-r--r-- 941 bytes parent folder | download | duplicates (6)
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
#!/usr/bin/env ipescript 
-- -*- lua -*-
----------------------------------------------------------------------
-- Add stylesheet
----------------------------------------------------------------------
--
-- Run this script as "ipescript add-style <sheet.isy> <figure>"
-- 
-- It adds the stylesheet <sheet.isy> to the Ipe document <figure>.
--
----------------------------------------------------------------------

if #argv ~= 2 then
  io.stderr:write("Usage: ipescript add-style <sheet.isy> <figure>\n")
  return
end

local sheetname = argv[1]
local figname = argv[2]

local nsheet = assert(ipe.Sheet(sheetname))
local doc = assert(ipe.Document(figname))
doc:sheets():insert(1, nsheet)
assert(doc:runLatex())

-- make a backup of original
local f = assert(io.open(figname, "rb"))
local data = f:read("*all")
f:close()
f = assert(io.open(figname .. ".bak", "wb"))
f:write(data)
f:close()

-- now write updated figure back
doc:save(figname)