I have an R function which returns a latex fragment, which I'd like to insert into my org file. Here's what I tried, which just inserts the latex source:

#+BEGIN_SRC R :exports none :results silent
fitted <- lm(dist ~ speed, data=cars)
stargazer(fitted, out='fitted.tex')

#+INCLUDE: "fitted.tex" src latex

The latex output renders fine if I manually paste it into the org file between #+BEGIN_LATEX and #+END_LATEX markers. Here it is for reference:

% Table created by stargazer v.5.2 by Marek Hlavac, Harvard University. E-mail: hlavac at fas.harvard.edu
% Date and time: Wed, Mar 28, 2018 - 04:44:03 PM
\begin{table}[!htbp] \centering 
\hline \\[-1.8ex] 
 & \multicolumn{1}{c}{\textit{Dependent variable:}} \\ 
\\[-1.8ex] & dist \\ 
\hline \\[-1.8ex] 
 speed & 3.932$^{***}$ \\ 
  & (0.416) \\ 
  & \\ 
 Constant & $-$17.579$^{**}$ \\ 
  & (6.758) \\ 
  & \\ 
\hline \\[-1.8ex] 
Observations & 50 \\ 
R$^{2}$ & 0.651 \\ 
Adjusted R$^{2}$ & 0.644 \\ 
Residual Std. Error & 15.380 (df = 48) \\ 
F Statistic & 89.567$^{***}$ (df = 1; 48) \\ 
\hline \\[-1.8ex] 
\textit{Note:}  & \multicolumn{1}{r}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01} \\ 
  • 2
    You could also write the output to stdout instead of the .tex file. The results would then show up in a #+RESULTS: block after your SRC block, and you could then :exports results in your SRC block header. No external file is cleaner.
    – mankoff
    Commented Mar 28, 2018 at 22:45

2 Answers 2


You should use the export tag instead of the src tag:

#+INCLUDE: "fitted.tex" export latex

Documentation explains almost nothing, so I just tested and it works.


Although it's not necessary for this particular question, I will also add that if you need the code to be inserted into the preamble, then you can use a command such as the following:

#+LaTeX_HEADER: \input{somefile.tex}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.