Is there a way to style or format the python chunks in Rmarkdown.
To style R chunks I use the option tidy.method = "styler" that calls the styler package. Is there a way to do the same for the python chunks?
Related
Im using GBQ, I want to export the results of a query into CSV file.
The data is larger than 20M lines so Im using this option :
In my query results I have some text in french, that is being saved in bad encoding to CSV.
Is there a way to define the encoding on Saving step in GBQ ?
Thank you
You can write simple Python script (or another language that made you feel comfortable) to query and save the result by using Python code. So you can use any encoding you want to save your result to CSV file.
Is there a way to reformat all code chunks in an Rmarkdown document?
I have Rmarkdown documents which need code reformatting but I can't select all and use the Rstudio reformat code.
The package styler can reformat Rmarkdown files.
library(styler)
style_file("badlyFormattedFile.Rmd")
It can also reformat all Rmd or R scripts in a directory using
style_dir("directoryWithUglyFiles")
In bookdown, it appears that \textcolor in latex is not recognized when I try to compile using
bookdown::render_book('bookdown::epub_book')
even though I have added \usepackage{xcolor} into the preamble.tex file.
Is there a reason for this?
Let's have a look at the way the document is processed. I will leave out processing by the knitr and R Markdown packages and focus on pandoc, which is the final step when converting from Markdown to any other format.
Pandoc first parses the document into an internal, intermediate format. We can inspect that format by choosing native as the target format. So when we feed \textcolor{red}{Mars} to pandoc, it will show us the native representation:
$ printf '\\textcolor{red}{Mars}' | pandoc --from=markdown --to=native
[Para [RawInline (Format "tex") "\\textcolor{red}{Mars}"]]
What this means is that, without going into too much detail, pandoc recognizes \textcolor... as a raw LaTeX command embedded into Markdown. It does not try to parse the LaTeX any further, as it was told to read Markdown, not LaTeX. This raw LaTeX snippet will be included in the output when producing output of a format which supports inclusion of LaTeX. The snippet is left out by pandoc when generating HTML/EPUB, as including it would not have the intended effect.
So can we convince pandoc to continue parsing, and does pandoc know how to translate \textcolor from LaTeX to HTML?
The second question is easy to answer by converting the LaTeX to HTML via pandoc:
$ printf '\\textcolor{red}{Mars}' | pandoc --from=latex --to=html
<p><span style="color: red">Mars</span></p>
That looks good, so let's make pandoc parse the raw LaTeX snippets as the next step. Pandoc has a feature called Lua filters which allow us to modify the internal document representation programmatically. Here is such a filter which will parse the raw LaTeX commands:
function RawInline (el)
if el.format == 'tex' then
local blocks = pandoc.read(el.text, 'latex').blocks
return blocks[1] and blocks[1].content or el
end
end
Save this code to a file parse-latex.lua and make your document processing pipeline use this file:
---
output:
bookdown::epub_book:
pandoc_args: ['--lua-filter=/path/to/your/parse-latex.lua']
---
The colored text should now show up in your epub book.
I have 3 standalone c++ componenets i.e Driver , Parser and Translater
Driver connects to data source and fetches data , parser parses data and Transform converts the data as needed i.e the flow of data looks like below
Driver.Out --> Parser.In -- Parser.Out --> Translator.In
I want to write a runtime interpreter which ties these components with Queues and produce the desired output.
I wanna use this interpreter as many times as possible , each being a independent Process
Any thoughts will be highly appreciated
Did you consider embedding an interpreter like lua inside your application, or embed your application as an extension for ocaml or python
But I don't understand exactly your question.
Use flex and bison. A good book on how to write interpreters or compilers with them is Flex & Bison: Text Processing Tools by John Levine.
I need to write a program that displays a PDF which a third-party supplies. I need to insert text data in to the form before displaying it to the user. I do have the option to convert the PDF in to another format, but it has to look exactly like the original PDF. C++ is the preferred language of choice, but other languages can be investigated (e.g. C#). It need to work on a Windows desktop machine.
What libraries, tools, strategies, or other programming languages do you suggest investigate to accomplish this task? Are there any online examples you could direct me to.
Thank-you in advance.
What about PoDoFo:
The PoDoFo library is a free, portable
C++ library which includes classes to
parse PDF files and modify their
contents into memory. The changes can
be written back to disk easily. The
parser can also be used to extract
information from a PDF file (for
example the parser could be used in a
PDF viewer). Besides parsing PoDoFo
includes also very simple classes to
create your own PDF files. All classes
are documented so it is easy to start
writing your own application using
PoDoFo.
iTextSharp is a free library that you can use in .Net applications. Take a look at the iText page - that is for the iText project, which is a Java library. iTextSharp is part of that project, and is a port to C# and .Net.
Consider Python It have a lot PDF librarys (both creating and extracting) eg:
http://pypi.python.org/pypi/pdfsplit/0.4.2
http://pypi.python.org/pypi/JagPDF/1.4.0
http://pypi.python.org/pypi/pdfminer/20091129
http://pypi.python.org/pypi/podofo/0.0.1
http://pypi.python.org/pypi/pyFPDF/1.52
There are also good tools for using C/C++ code in Python and to create .exe form Python scripts. If you decide to use different language consider Python as prototyping language!