How can user macros and packages be included in the latex rendered in markdown cells in ipython?
e.g.:
\usepackage{amssymb}
\newcommand{kms}{\ensuremath{\mathrm{km~s}^{-1}}
It is possible to define macros in cells with markdown. Just put the \newcommand between $'s:
$\newcommand{kms}{{\mathrm{km~s}^{-1}}}$
(Note that I removed the \ensuremath command, as it is not accessible.)
In any following statement (in the whole notebook) you can call the macro (in a markdown cell only, of course):
$\kms$
I do not know a way to include extra packages :( If you ever learn how, I would also encourage you to use the siuntx package to format units.
The Html notebook use mathjax to render LaTeX, I suggest reading its doc to know wether it is possible and how.
Related
I'm trying to write a scientific article and the associated supplementary materials entirely in RStudio with rmarkdown.
It seems clear that book down is the way to go to cross-reference between files (https://stackoverflow.com/a/38884378/576684), but I also would like to be able to reference figures produced in one pdf in the other pdf.
Although my latex has got quite rusty with time, I imagine it could be achieved as follows:
compile the article tex and SuppMat tex a first time using rmarkdown::render()
compile these tex files from the command line in order to keep the corresponding .aux file with their references (missing references won't be resolved at this time)
recompile the 2 tex files from the command line another time where all references should now be resolved
Is it a reasonable way to do it? am I overlooking something simpler?
In any case, it requires:
a different numbering of figures in each pdf file (covered by https://stackoverflow.com/a/51337664/576684)
to prevent rmarkdown from trashing the .aux files (it seems that pandoc doesn't allow this, hence the need to create the aux file using standalone latex)
to tell latex to use the additional .aux file if it is found (probably using header-includes: in the YAML header). how can I achieve that?
Thank you very much for your help!
It turns out that the xr package is one way to go: https://texblog.org/2016/08/23/adding-references-from-an-external-file/
so this works from R:
rmarkdown::render("myarticle_ms.Rmd",
bookdown::pdf_book(base_format=rticles::plos_article),
clean=FALSE)
rmarkdown::render("myarticle_SM.Rmd",
bookdown::pdf_book(base_format=rticles::plos_article),
clean=FALSE)
tinytex::pdflatex("myarticle_ms.tex", clean=FALSE)
tinytex::pdflatex("myarticle_SM.tex", clean=FALSE)
tinytex::pdflatex("myarticle_ms.tex")
tinytex::pdflatex("myarticle_SM.tex")
with the following in the YAML header of myarticle_ms.Rmd (and the corresponding one the SuppMat file header):
header-includes:
\usepackage{xr} \externaldocument{myarticle_SM}
Hope it makes life easier for a few others :)
I'm writing a manual of sorts in LaTeX for some software. I'm constrained to use the article class. I must include docs of individual c++ classes in the manual. I'm looking at doxygen for this, but I've never used doxygen (if there's a better way, let me know).
I can get doxygen to produce a nice LaTeX (--> pdf) file of my entire project. But what I'd like to do is somehow extract the LaTeX source for each class and drop it into my LaTeX manual source at the appropriate place.
I've tried putting all the preamble stuff from refman.tex (generated by doxygen) in my preamble, and then later in the document using \input to include the tex file of an individual class. After cleaning up a few conflicts, I get to one that I don't know how to get past. The doxygen-generated doxygen.sty file makes reference to \chaptermark, but I believe that this is a macro defined in the book class.
So 1.) Am I going about this all the wrong way? 2.)Is it possible to force Doxygen to produce code in the article class? 3.) Anything else?
-garyp
You can make doxygen produce a document that uses the article document class by setting COMPACT_LATEX to YES in your doxygen config file.
I'm producing a set of documents in LaTeX, and I would like to provide a single, global bibliography page for the whole set. This is because each document is page-limited: I don't want to take up space with references at the bottom of each one.
This means in each case, I would like to cite in the text, but not produce a reference at the end. I am using bibtex/natbib to handle the referencing.
Simplest example:
\documentclass[]{article}
\bibliographystyle{/usr/share/texmf/bibtex/bst/natbib/plainnat.bst}
\usepackage{natbib}
\begin{document}
In \citet*{MEF2010} I described the method.
\bibliography{bibliography.bib}
\end{document}
How can I do this? Essentially I just want it to cite correctly:
In Bloggs, Blagg and Blog (2010) I described the method.
But not add a references section at the end. Any ideas?
Thanks,
David
Instead of using \bibliography{bibliography.bib} you can try \nobibliography{bibliography.bib}.
You still need to enter the path so it can make the cross-references.
It happens due to missing packages. If you want to resolve the problem then enable the automatic installation packet. After that,First, you run the BibTeX file and generate the Pdf file (instead of pdfLatex file) and then pdfLatex to Pdf
Is there a way, in a LaTeX style/class file, to detect which output device is being used (or at least which capabilities it has)? The reason is, I'm writing a class file in which I want to use some Postscript-specific packages (e.g. pstricks) if Postscript is available, but if I just write
\RequirePackage{pstricks}
then of course bad things happen if I'm compiling the document with pdflatex. So ideally I'm looking for something I can use like
\if#postscriptokay\RequirePackage{pstricks}\fi
It seems like this must be possible because I know packages like pgf can change their behavior to use appropriate graphics commands based on the output device, but I've done some Google searches and checked in my LaTeX book and haven't found a way.
\usepackage{ifpdf}
\ifpdf
% nothing
\else
\RequirePackage{pstricks}
\fi
You can detect pdfTeX like this (this is what ifpdf.sty does):
\makeatletter
\ifx\pdfoutput\#undefined
no pdfTeX
\else\ifnum\pdfoutput<1
pdfTeX is outputting a .dvi file
\else
pdfTeX is outputting a .pdf file
\fi\fi
graphicx.sty, hyperref.sty and pgf.sty have their own autodetection mechanisms built in. They load a different driver file (like pdftex.def and hpdftex.def) based on the autodetection and the package option. If you load any of these in your .tex file, try to get the information which driver they loaded. The relevant driver files are:
/usr/share/texmf/tex/generic/pgf/systemlayer/pgfsys-*.def
/usr/share/texmf-texlive/tex/latex/hyperref/hpdftex.def
/usr/share/texmf-texlive/tex/latex/graphics/*.def
/usr/share/texmf-texlive/tex/latex/pdftex-def/pdftex.def
The name of the driver for pgf.sty and graphicx.sty is stored in the macro \Gin#driver. You can inspect this macro after loading any of these packages.
Have a look at packages pstool and auto-pst-pdf. They are here to help use pstricks and friends with pdfLaTeX.
If you are using the KOMA-Script package (which I can really recommend, unless you need to use a different style of course) you already have a macro for this: \ifpdfoutput{pdf output}{dvi output} is defined in that package. If not, use the ifpdf package as has already been mentioned.
So far the hyperref package in LaTeX has automatically linked all the items in my report correctly. But there is one that did not get linked properly, possibly because I manually added it to the table of contents like this:
\addcontentsline{toc}{chapter}{Bibliography}
How do I fix this?
You have to use the \phantomsection macro just before or after the \addtocontentsline. This instructs hyperref to add an anchor at that point. Also, take into account that you have to run LaTeX several times to make this anchor to be in the exact place.
If you're using a standard LaTeX document class, such as report, you can use the tocbibind package, and then you won't need the \addcontentsline command and the hyperlinks should work correctly. From the documentation:
The tocbibind package enables the titles of the Table of Contents, the List of Figure, the List of Tables, the Bibliography and the Index all to be added to the Table of Contents.
I'd also suggest looking at the memoir class, which also solves this problem. It's intended to be a replacement for the standard report and book classes, and provides lots of options and commands for customisation.