I have a Ruby script that produces a Latex document using an erb template. After the .tex file has been generated, I’d like to make a system call to compile the document with pdflatex. Here are the bones of the script:
class Book
# initialize the class, query a database to get attributes, create the book, etc.
end
my_book = Book.new
tex_file = File.open("/path/to/raw/tex/template")
template = ERB.new(tex_file.read)
f = File.new("/path/to/tex/output.tex")
f.puts template.result
system "pdflatex /path/to/tex/output.tex"
The system line puts me in interactive tex input mode, as if the document were empty. If I remove the call, the document is generated as normal. How can I ensure that the system call isn’t made until after the document is generated? In the meantime I’m just using a bash script that calls the ruby script and then pdflatex to get around the issue.
The
File.newwill open a new stream that won’t be closed (saved to disk) until the script ends of until you manually close it.This should work:
Or a more friendly way:
The
File.openwith a block will open the stream, make the stream accessible via the block variable (fin this example) and auto-close the stream after the block execution. The'w'will open or create the file (if the file already exists the content will be erased => The file will be truncated)