24

0. tl;dr knitr is preferable to Sweave, and ezknitr is a wrapper around knitr that is probably worth using—especially if you are only building documents from the command line (but this limits you to R Markdown; see below); I don't think there are IDEs that have integrated ezknitr use (at least not at the time of writing)—because it makes it easier to ensure ...


18

The baseline approach is just to keep them separate. My work flow on a recent paper was as follows: I wrote an R script to calculate the statistics and generate (a) charts and (b) tables of numbers. The script produced charts either as eps (which I used with LaTeX) or as png (which were needed for the online version of the paper). The charts had long ...


12

You have to use a different literate for starred ones: literate= *{-}{{{\color{ipython_purple}-}}}1, If you add more literates after this one (without the star) they will behave as if they were starred. For example literate= *{-}{{{\color{ipython_purple}-}}}1 {?}{{{\color{ipython_purple}?}}}1, Also, the quotes at the beginning of the listing are due to ...


10

With \lstdefinestyle you can define as many styles as you wish; then you can use \lstnewenvironment to define new listing environments using those new styles; in this way you can easily change the styles for your listings as required. You can still use \lstset to set general settings (applicable to all the listings). A simple example: \documentclass[]{...


9

It's a bit hard to answer as the question has no context as to the desired workflow, do you want to generate the documentation from the source, or the source from the documentation (the normal sense of "literate-programming)) or maintain them separately but make it easier to keep them in sync. Whichever you choose, there are some things you could do to make ...


8

There is other literate programming tools that can be used to prepare TeX macros. I have experience with using noweb (Norman Ramsey's web) but have heard about another option muweb. Both noweb and muweb provide a language agnostic implementation of cweb and ctangle. Since noweb is language agnostic it provides an extension mechansim, so that external tools ...


8

A possible solution, using an align* environment. \documentclass{article} \usepackage{amsmath} % for 'align*' env. \begin{document} \begin{align*} &\quad A + ( B + C ) \\ =&\qquad \text{\{ Associativity \}} \\ &\quad (A + B) + C \\ =&\qquad \text{\{ Commutativity \}} \\ &\quad (B+A)+C \end{align*} \end{document}


8

A more “primitive” way in LaTeX, that also avoids the issues with grouping one gets with \foreach, would be \makeatletter \def\basiccolors{% black,blue,brown,cyan,darkgray,gray,green,lightgray,lime,% magenta,olive,orange,pink,purple,red,teal,violet,white,yellow% } \def\do@def#1{% \expandafter\newcommand\csname command#1\endcsname{% \textcolor{#1}{...


7

Are there other approaches? Yes, lazyWeave. While Sweave and knitr process LaTeX files with R chunks (R noweb files), lazyWeave can create LaTeX documents from scratch. Beside this, it is worth to note that other R packages as the famous xtable and Hmisc can produce some type ofLaTeX code. What are the merits? To be honest, I never used lazyWeave, ...


5

You have to write the data in the .aux file for having the information available at the next run; we exploit the fact that the .aux file is read as part of \begin{document}, so \manuallanguages will have the requested value (at the next run) when \maketitle is issued. \documentclass{article} \makeatletter \newcommand{\manuallanguages}{\@gobble} % ...


5

Assuming that you are using poly style, one possibility is to use the \savecolumns / \restorecolumns commands described in section 8.8 of Guide2lhs2TeX. However, this requires that there is a token in the first code block that is indented as much as the code in the second code block; e.g., in your example, you could put the where on the next line: I'm going ...


5

with use of tikzmark library is simple: \documentclass{article} \usepackage{tikz} \usetikzlibrary{calc, positioning, tikzmark} \begin{document} text \tikzmark{As}text\tikzmark{Ae} text text text t\tikzmark{Bs}a\tikzmark{Be}xt \begin{tikzpicture}[overlay, remember picture] \coordinate[below=0.5ex of $(pic cs:As)!0.5!(pic cs:Ae)$] (a); \coordinate[below=0....


4

You could use \@for or an expl3 list but often a more convenient (and a lot more efficient in terms of expansions) technique is to use a different structure which allows you to execute the list with no separate loop macro, this is explained in appendix D of the texbook and used in several places in latex (look for \@elt usage) I'll use \\ here. \...


3

Some critiques of Thruston's alternative approach v knitr: It is actually possible to create multiple outputs of plots from the one .Rnw file (only including the pdf version in the LaTeX output). In a report I did recently, each time the document was compiled, each plot was rendered as: a. a pdf b. a png c. a Windows Enhanced Metafile d. a PowerPoint ...


3

Here is a solution. I make it only with 2 tags but you can add more \documentclass{article} \newif\ifbytag %-------------- here we make the chice by tag or by date (if false) \bytagtrue %\bytagfalse \newcommand{\cartag}{car maintainence} % may one add formatting : bold, space ... \newcommand{\worldtag}{world domination} % may one add formatting \...


2

It looks we cannot activate one-letter and two-letter sequences (literate) at the same time in the listings package. Therefore, I created a small patch in Lua. It takes input file written in Verilog language (let it be the verilog-input.v file starting with \begin{lstlisting} and ending with \end{lstlisting}), it finds critical spots and changes them. The ...


2

I can provide you solution at the TeX level. Under normal circumstances I would use the listings package which can format the Haskell language, but this question looked like a challenge to try something new. The problem is that the indentation of lines starts after one or more regular lines in your blocks of code. I indent that part of code manually by ...


2

Try the following. If it suits you, I'll flesh out my answer a bit more. \documentclass{article} \usepackage{listings} \makeatletter \lstset{ language=Python, moredelim=*[s][\lst@stringstyle]{"""}{"""}, moredelim=[s][\lst@commentstyle]{<<}{>>}, showstringspaces=false, } \makeatother \begin{document} \begin{lstlisting} def expand(): ...


2

You can insert arbitrary LaTeX commands in your preamble after %include polycode.fmt, including font commands. The polycode.fmt file does set up a few commands that change the font to a specific family, so it is necessary to override them with \renewcommand. This example sets up the output to use unicode-math, and selects TeX Gyre Pagella (a Palatino clone)...


2

For the time being, I am going with the standard solution that prevents any code chunk from ever being broken. But to enable line breaks in the middle of paragraphs, I am sprinkling \stdbreak liberally throughout paragraphs, where \stdbreak is defined as follows: \newcommand\vfilbreak[2][200]{% \vskip 0pt plus #2 \penalty -#1 \vskip 0pt plus -#2 \relax} \...


1

I extended the markdown package (specifically, the markdown.dtx which is then compiled into the various files of the package) for this specific project in the following way. 1 file changed, 41 insertions(+) markdown.dtx | 41 +++++++++++++++++++++++++++++++++++++++++ modified markdown.dtx @@ -14079,6 +14079,41 @@ parsers.fencedline = function(char) ...


1

(The macro \list is already defined and in use for the list-environment in LaTeX 2e. Therefore in the example below, the macro \MyList is defined and used instead.) You can, e.g., easily turn the matter into a matter of expanding the macro that holds the list and afterwards exchanging arguments. With the example below, \expandafter is used for expanding ...


1

In the dtx code as posted there are no tabs (as the site changes them to spaces) but if I put tabs back in the Makefile section and modify the .ins to look like \catcode9=12 \generate{ \file{Makefile}{\from{\jobname.dtx}{make}} Then tabs are written to the Makefile if I use luatex on the .ins. (The resulting file gets called Makefile.tex though. (...


1

The actual issue didn't lie in the combination of \foreach with a string, but rather in PerlTex returns not being interpreted correctly. Once I realized the problem, I created a workaround by not returning the actual string, but rather a \renewcommand. I added a functioning example for posterity: \documentclass[12pt, a4paper]{article} \usepackage[T1]{...


1

Here is the location on my PC D:\texlive\2016\texmf-dist\tex\plain\base and find the plain.tex file, that is the corresponding file described in TeXbook.


1

You can simply change the definition of \fwbeginmacro and \fwendmacro to make ^^Y an ignored character. \def\fwbeginmacro{\begingroup\fwparskipoff\bigskip\catcode`\^^Y=9 } \def\fwendmacro{\fwparskipon\par\endgroup} You can also add a new command \def\fwignorexxv{\catcode`\^^Y=9} and use this macro at the begin of the code just after \fwbeginmacro. If it ...


1

An old question without an accepted answer and you find a kind of a solution already. But as it is not closed yet I want to share my ideas. The command \filbreak is not your friend. The TeXbook states The most interesting macro that plain \TeX provides for page make-up is called \filbreak. It means, roughly, "Break the page here and fill the bottom ...


Only top voted, non community-wiki answers of a minimum length are eligible