# Organizing Latex macro file

I'm looking for a way to organize and share my LaTeX macros file. Ideally, I would like to write an org-mode file to export

• as a documentation file in html or pdf for sharing
• as a bare macros.tex containing only the macros

For instance, the org-file would look like

* Number sets

lorem ipsum

#+BEGIN_SRC latex
\def\R{{\mathbf R}}
\def\C{{\mathbf C}}
\def\N{{\mathbf N}}
#+END_SRC


The output in LaTeX would contain only

\def\R{{\mathbf R}}
\def\C{{\mathbf C}}
\def\N{{\mathbf N}}


The output in html would display

Number sets

Lorum ipsem

\def\R{{\mathbf R}}
\def\C{{\mathbf C}}
\def\N{{\mathbf N}}


Any idea ?

• Look up tangling in the Org mode manual. – NickD Feb 27 '20 at 22:16

Found it. Thanks. The solution is

#+BEGIN_SRC latex :tangle yes :exports code
\def\R{{\mathbf R}}
\def\C{{\mathbf C}}
\def\N{{\mathbf N}}
#+END_SRC


When using the function org-babel-tangle I get my bare .tex file and normal export function of org-more yields the html file.

• BTW, you can accept your own answer (assuming it works for you :-)). That is a good thing to do: it shows future visitors who might have the same or similar question that the answer actually answered the original question and therefore is a good bet to answer their question. – NickD Feb 28 '20 at 19:06