TeX compiler in ruby - ruby

I'm looking for a gem that allows to compile tex files (TeLaTeX or just LaTeX) into pdf. I don't need any templating or partial rendering, just simple compiler. Is there any bindings for latex2pdf or something.

Are you looking for a TeX-Compiler written in ruby or a ruby script, that calls LaTeX?
If you look for the 2nd one:
http://rubygems.org/gems/rake4latex
Defines a rake-task to generate a pdf, based on tex-sources. It checks, how many TeX-runs are needed, makeindex, bibtex... is done if required.
Supports splitindex, gloss...
Can be used with LaTeX, pdfLaTeX, XeLaTeX...

Can't you just call the command line directly with backtick notation?
`latex2pdf <options>`

It shows that TeX's syntax is so horrible flexible, that you actually will need TeX or any of its variants to interpret TeX files in general.
So actually calling the command line pdflatex or xelatex (or any wrapper around this, like in peakxu's answer) is the best bet here.
I have no idea if someone packaged a TeX distribution (like TeX Live) into a Ruby Gem, I suppose not.

Related

julia: static analyzer/linter for the command line

im looking for a shell command-line tool to lint julia scripts (a static analyzer), eg.
local:~ $ linter(myjuliascript.jl)
which will produce its output to terminal => text with linter results = either
// messages inlined with text of myjuliascript.jl or
...
...
// messages indicating line numbers of myjuliascript.jl
...
...
i found this, https://github.com/tonyhffong/Lint.jl, but it does not look promising (does not compile).
question: do you know of any good-quality command-line tool with which to lint julia scripts?
id rather avoid plugins to IDE's, since im a little tired of IDEs; often they are too much kung-fu-fighting with too little benefit. eg. tried to get the VS code julia linter working, no luck; VS code, julia linter doesn't work (on mac)
The closest thing currently available appears to be https://github.com/julia-vscode/StaticLint.jl. While you could technically call this from the command line if so desired using, julia -e, the interface would not seem to be very conducive to that sort of usage.

Code Formatting for the ReadTheDocs System

I'm using Read the Docs for the first time. I'm writing docs for a command line system, and my "code samples" include a log of shell output. The shell output ends up looking like this
That is -- the service (or my use of it?) is trying to format this example of running a shell command as though it was source code, and is treating the magento2:generate as though it was a class constant.
Can I control which code blocks get source code formatting in read the docs? I've tried setting no base language in the admin, but it doesn't seem to have an effect. Or is this something I need to control at the mkdocs of sphinx level? (read the docs works by turning your markdown or sphinx files into nice HTML files) Or something else? Or am I out of luck?
You need to define the "language" of the code block in your source document. Both Sphinx and MkDocs will attempt to guess the language, which often is good enough. However, on occasion, it will guess incorrectly and result in weird highlighting. To avoid that, both implementations provide a mechanism to manually define the language of each code block.
Sphinx
For Sphinx, you can use the code-block directive and include the "language" of the block:
.. code-block:: console
You shell commands go here
In the above example, I used console for the a shell session. The alias shell-session would work as well. Note that the alternative lexer bash (and its aliases: sh, ksh, zsh, and shell) woudl not strictly be appropriate as they are for a shell script, whereas you are displaying both the command and theoutput in a shell session.
A complete list of supported language codes can be found in the Pygments documentation.
MkDocs
MkDocs makes use of the Fenced Code Block Markdown extension to define the "language" of a code block:
``` shell
Your shell commands go here
```
As MkDocs uses highlight.js rather than Pygments, the list of supported languages is different. Therefore, I used shell (for a shell-session) in the above example.

Option parsing standard

I've seen a number of option parsing libraries out there for ruby, but they all come with weird constraints about them.
'executable' gem claims that all command line binaries must have a syntax "binary
'micro-optparse' can't handle trailing list of filenames and requires you have defaults for all non-boolean commands. Strange.
Some other one I used made it impossible to run a command without arguments.
And so on and so on. And I don't want to parse ARGV myself.
Is there anything close to a specification or standard for command line options and arguments? And then what option parsing library complies to that standard?
Do you know about optparse? It's included in stdlib - as standard as it gets.
But there is no unix standard set in stone as to parsing command-line parameters.
You should define your requirements more clearly and then choose a library that suits them.
There's no standard I have ever heard of, but AFAIR Trollop was started out of the frustration with the other command line parsers.
+1 for Michael Kohl's mention of Trollop. Trollop makes it very easy to write command line options that conform to the gnu style.
I wrote a simple self-contained example in How do I make a Ruby script using Trollop for command line parsing?.

Syntax Checking with unsupported languages

I have some files that have a particular syntax that is similar to ada (not identical though), however I would like to verify the syntax before going and running them. There isn't a compiler for these files, so I can't check them before using them. I tried to use the following:
gcc -c -gnats <file>
However this says compilation unit expected. I've tried a few variations on this, but to no avail.
I just want to make sure the file is syntactically correct before using it, but I'm not sure how to do it, and I really don't want to write an entire syntax checker just for this.
Is there some way to include an additional unsupported language to gcc without going through a recompile? Also is this simply a file that details to gcc what the syntax constructs are, or what would be entailed? I don't need a full compile, only a syntax check.
Alternately, are there any syntax checkers I can use that I can update an ada syntax check with the small number of changes required for this language?
I've listed Ada as a tag, since the syntax is nearly identical, and finding something that will do ada syntax checking without compiling will be a 90% solution for me.
You could try running the files through gnatchop first. The GCC Ada compiler is rather unique in that it expects filenames to match up with the main unit names inside the file. That may be what your error message is trying to say.
gnatchop will go through any files you give it and write out Ada source files with the appropriate names to make gcc happy (even splitting files into multiple files if needed).
Another option you might be interested in is OpenToken. It is a parser construction toolkit, written in Ada, that allows you to build your own parsers fairly easily. It comes with a syntax recognizer for Ada, so you may just be able to tweak that a bit for your needs.

SWeave with non-R code chunks?

I often use Sweave to produce LaTeX documents where certain chunks are produced dynamically by executing R code. This works well - but is it also possible to have code chunks that are executed in different ways, e.g. by executing the code in the shell, or by running Perl, and so on? It would be helpful to be able to mix things up, so I could do things like run some shell commands to fetch some data, run some perl commands to pre-process it, and then run R commands to analyze it.
Of course I could use all R chunks and use system() as a poor-man's substitute, but that doesn't make for very pleasant reading in the document.
The new new thing (for multi-language, multi-format) docs may be dexy.it which for example these guys at opengamma.org use as the backend.
Ana, who is behind dexy, is also giving a lot of talks about it so also look at the dexy blog.
It's not directly related to Sweave, but org-babel, which is part of Emacs org-mode, allows to mix code chunks of different languages in one file, pass data from one chunk to another, execute them, and generate LaTeX or HTML export from the output.
You can find more informations about org-mode here :
http://www.orgmode.org/
And to see how org-babel works :
http://orgmode.org/worg/org-contrib/babel/
There is certainly no easy way to do this other than through either foreign language interfaces from R (maybe through inline if it's supported), or system(). For what it's worth, I would just use system(); that should be easy enough.
You can see this previous question about having a Sweave equivalent for Python, where one of the respondents actually creates a separate interface. This can give you a sense what what it would take to embed other languages which may not already be supported. At a minimum, you have to do major hacking on the Sweave driver.
Do you know emacs" org-mode and, more specifically, Babel? If you already know Emacs or are willing to switch to Emacs, then org-mode and Babel are the answer to your question(s).
For instance, I am currently working on a document which contains some shell-scripts, does computations with R and creates flow charts with dot (graphviz). Org-mode can export a variety of formats, e.g. LaTeX (that's what I use).
There is the StatWeave project which uses java rather than R to do the weaving, but will run multiple programs instead of just R. I don't know how hard it would be to get it to do Perl or other programs like that, but the homepage indicates that it already works with R, SAS, Stata, and others:
http://www.cs.uiowa.edu/~rlenth/StatWeave/

Resources