folding sections denoted by headers in rmarkdown - r-markdown

I have been unsuccessful at getting Rmarkdown to fold sections denoted by a #section_header. I know code folding is great, but my goal is to be able to compare results across a number of different analytic pipelines without having to scroll all over the place to find what I am looking for. If I could fold each iteration of my analyses neatly into a foldable section, then I would be able to easily compare any two pipelines, while ignoring the rest. I've seen a bit posted about how to implement this in a pdf output but does anyone know how to implement something like this in an html output?
Thanks in advance.
-N

You want to slide whole sections, not just code -- otherwise an HTML notebook would probably do it.
So take a look at this Gist, where I cobbled something together using a little bit of jQuery, probably from this answer here:
<script src="https://gist.github.com/flynn-d/b756e512f5be7f553aad007f0ac37220.js"></script>
Link to Gist

Related

Generate inline rather than list-style footnotes in Pandoc Markdown output?

When converting from some format (say, HTML or Docx) to Markdown in Pandoc, is it possible to render all footnotes in the inline style ("this is the main text^[this is a footnote]") rather than as numbered references with a corresponding list at the end of the document? I want to work on my Markdown documents (converted from a Docx of my thesis) as master texts, but now if I add a new footnote it messes up the numbering.
Alternatively, is there another convenient way (i.e. not Pandoc) that this could be done? Cutting text in one part of a file and adding corresponding text in another part seems a bit beyond a simple regex.
Thanks in advance for any help.
EDIT: I've just hacked up an extremely simple Python script to do this, in case anyone else has the same issue.
Pandoc's Markdown syntax is quite flexible about footnotes:
The footnotes themselves need not be placed at the end of the document. They may appear anywhere except inside other block elements (lists, block quotes, tables, etc.).
Like:
Here is a footnote reference[^1] and some more text.
[^1]: Here is the footnote.
Here's the next paragraph.
However, the Markdown Writer (the module that generates markdown files, as opposed to reading them) currently simply places all of them at the end of the document. But this could be implemented behind a flag, similar to the --reference-links flag. Feel free to submit an issue or pull request!
Inline footnotes and references are quite nice for writing and editing markdown documents, but cumbersome for reading them.
I used ltrgoddard's inliner with success to process several files that I use with pandoc and latexmk to produce PDF. inliner works well for transforming end-style references to inline style references in an already-written document.
Cross references to other questions and clues for posterity:
Convert markdown links from inline to reference
Vim plugin for adding external links
Also see http://drbunsen.github.io/formd/
and https://instant-thinking.de/2014/02/20/markdown-footnotes-with-vim/ for more info re: formd, which should work for converting inline references end-style references, and vice-versa.
Note that formd works on URLs and ignores footnotes, so this may be seen as a similar project (with different goals) but not an alternative.

regex to separate HTML GET parameters

How can I use a regular expression to separate GET parameters in a URI and extract a certain one? Specifically, I'm trying to get just the v= part of a YouTube watch URI. I've come up with youtube.com\/watch\?(\w+=[\w-]+&?)*(v=[\w-]+)&?*(\w+=[\w-]+&?)*, but that looks awfully repetitive. Is there a better (shorter?) way to do this?
A simplified regex :
^(?:http://www.)?youtube.[^/]+?/watch?(.?)(v=([^&]+))(.)$
I know there are a lot of similar questions out there, but none has quite what I wanted. I'm looking for something capable of pulling out just the video ID—regardless of whether it's first in the parameter list, last, or buried in between others. Nothing I've seen has worked quite like that yet.
For reference, I'm using this web app for testing, and this set of test URIs:
http://www.youtube.com/watch?v=XXXXXXXXXXX
http://www.youtube.com/watch?v=XXXXXXXXXXX&feature=results_video&playnext=1&list=XXXXXXXXXXXXXXXXXX
http://www.youtube.com/watch?feature=player_embedded&v=XXXXXXXXXXX#!
http://www.youtube.com/watch?annotation_id=annotation_xxxxxx&feature=iv&src_vid=XXXXXXXXXXX&v=XXXXXXXXXX
Fellow Stack Exchangers, I propose the following regular expression to solve this:youtube.com\/watch\?(\S*)v=([\w-]+)

How can I highlight different types of file in dired mode in Emacs?

In a nutshell, I want to have different faces for some types of file in dired mode. I don't think it matters, but I am using Aquamacs.
The example I will use here is .tex files. If I can do it for .tex, then I can just apply the same structure to do create other faces for other types of files.
From what I understand, I have to create a variable, write a regular expression, then apply a hook. I read a bit about regex and so far I have
^(.+)\.tex$
I think my structure and regular expression are not really correct. I am not a programmer (though I have an interest on it), I have only been using Emacs for 2 weeks or so, so any help would be greatly appreciated.
What I need is at least the basic structure of what I have to do. I understand there may be modes already created that do something similar (such as maybe Wdired and Dired-X), and I would not complain if someone told me about them, but what I really want is to have an elisp code (either already written or that I can work on), as I plan on learning a bit of elisp to be able to write my own customisations and this would be a way to learn.
Thank you!
Since you want to learn how to do it, try checking out the extension dired+.el. This mode does a lot more than what you want, but it does add new faces. Specifically, look for the variable diredp-font-lock-keywords-1 and how it is used. That should get you going.
Other SO questions that seem relevant are:
Match regular expression as keyword in define-generic-mode
Highlighting correctly in an emacs major mode
A hello world example for a major mode in emacs?

Minimal noweb example with cross referencing

I'm trying to find a good literate programming tool. Let's just say it's not an easy decision. (The generic ones are too generic and the specific ones are too specific :) )
Among others, I've got noweb up and running but I'm having trouble getting output like I'd expect. The noweb wikipedia page has a minimal example that builds correctly with
noweave -index -latex hello.noweb > hello.tex && pdflatex hello && pdflatex hello
but there are no cross-references at the end of each chunk. For example, CWEB has pointers such as "This code is used in section 12." and "See also sections 5 and 7." Is this feature simply missing from noweb or am I missing a step in the compilation?
Is this feature simply missing from noweb or am I missing a step in the compilation?
Neither: noweb uses much more subtle markers than you are used to seeing from CWEB. In the case of the Wikipedia example, the 3rd chunk (1c) appears in chunks 1a and 1b. This information is condensed into a single '1', which appears in parentheses at the right hand side of the definition.
To get long cross-references in the CWEB style use
\noweboptions{longxref}
You should get, for that WP example, a reference to the license section from each of the two chunks in the Hello World section. You won't get any lists of chunks or identifiers at the end unless you tell latex about them.
To get a list of web chunks, try putting \nowebchunks near the end of the document (i.e., after the last chunk appears), and adding a -x switch to the noweb invocation.
To get a list of identifiers, try putting \nowebindex in a similar place.

parser: parsing formulas in template files

I will first describe the problem and then what I currently look at, in terms of libraries.
In my application, we have a set of variables that are always available. For example: TOTAL_ITEMS, PRICE, CONTRACTS, ETC (we have around 15 of them). A clients of the application would like to have certain calculations performed and displayed, using those variables. Up until now, I have been constantly adding those calculations to the app. It's pain in the butt, and I would like to make it more generic by way of creating a template, where the user can specify a set of formulas that the application will parse and calculate.
Here is one case:
total_cost = CONTRACTS*PRICE*TOTAL_ITEMS
So, want to do something like that for the user to define in the template file:
total_cost = CONTRACTS*PRICE*TOTAL_ITEMS and some meta-date, like screen to display it on. Hence they will be specifying the formula with a screen. And the file will contain many formulas of this nature.
Right now, I am looking at two libraies: Spirit and matheval
Would anyone make recommendations what's better for this task, as well as references, examples, links?
Please let me know if the question is unclear, and I will try to further clarify it .
Thanks,
Sasha
If you have a fixed number of variables it may be a bit overkill to invoke a parser. Though Spirit is cool and I've been wanting to use it in a project.
I would probably just tokenize the string, make a map of your variables keyed by name (assuming all your variables are ints):
map<const char*,int*> vars;
vars["CONTRACTS"] = &contracts;
...
Then use a simple postfix calculator function to do the actual math.
Edit:
Looking at MathEval, it seems to do exactly what you want; set variables and evaluate mathematical functions using those variables. I'm not sure why you would want to create a solution at the level of a syntax parser. Do you have any requirements that MathEval does not fulfill?
Looks like it shouldn't be too hard to generate a simple parser using yacc and bison and integrate it into your code.
I don't know about matheval, but boost::spirit can do that for you pretty efficiently : see there.
If you're into template metaprogramming, you may want to have a look into Boost::Proto, but it will take some time to get started using it.