Chapter 3
Latex specific HowTo

3.1 How to install TL 2022 pre test?
3.2 How to increase the setting dest_names_size using lualatex?
3.3 How to install garamond fonts
3.4 How to draw faces in Latex
3.5 How to see more context where the erorr generated came from?
3.6 How to include image in landscape mode?
3.7 How to spell check Latex document?
3.8 How to obtain external file information about Latex build
3.9 How to use minted
3.10 How to increase memory for Latex?
3.11 How to use Maple style sheets (packages) with texlive?
3.12 How to install and use pdf2htmlEX?
3.13 How to put image in a title page?
3.14 How to convert pdf to eps?
3.15 How to draw a baseline hairline for an equation?
3.16 How to find what changed in TexLive?
3.17 extracting selected pages from a pdf?
3.18 how to include files in Latex
3.19 combining complete documents into one
3.20 how to install lyx on Linux
3.21 using hyperlinks
3.22 page breaks
3.23 using tables
3.24 passing flag from command line to pdflatex and htlatex?
3.25 What levels are there? TOC configuration
3.26 TOC related
3.27 on fonts
3.28 pixels and Latex
3.29 on equations
3.30 How to upgrade latex once installed?
3.31 Things to do post Installation of texlive 2016 on Linux
3.32 Installation of texlive 2015 on Linux
3.33 Installation of texlive 2014 on Linux
3.34 installation of TeX Live 2013
3.35 on using multicols
3.36 How to place figures
3.37 Finding definitions of LaTeX control sequences?
3.38 wrapping text around figures
3.39 what tex editors to use?
3.40 How to define text block to use in more than one place?
3.41 adjusting text, parskip, parindent
3.42 How to reduce size of math in one place only?
3.43 How to hand written fonts and other fonts using xelatex?
3.44 How to use Times font for the whole document in Latex?
3.45 how to pass variable to latex to change the compile content?
3.46 how to generate Latex from other programming languages?
3.47 how to debug Latex?
3.48 How to find history of Tex? Family tree?
3.49 Where to put a style file that is downloaded and not part of TexLive?
3.50 How to convert pdf to eps?
3.51 what are values of extensions for images
3.52 How to include pdf pages as is in Latex
3.53 How to automatically build images needed for the latex file?
3.54 Some lualatex examples using Lua inside Latex

3.1 How to install TL 2022 pre test?

went to http://ftp.math.utah.edu/pub/tlpretest/ and downloaded the file install-tl-unx.tar.gz to new folder. Then did gunzip on it then tar -xvf on the tar file. Then cd to the install folder that is created.

Now to do the actual installation it is important to type this command by giving -reposity option else it will not work, since I have TL 2021 installed and I am trying to install TL 2022. So used this command

 sudo ./install-tl -repository http://www.math.utah.edu/pub/tlpretest/

Now it will make new folder for TL 2022 and install it there alongside the TL 2021.

3.2 How to increase the setting dest_names_size using lualatex?

This applies to any one using lualatex and encounters the dreaded error

sorry [number of destination names (dest_names_size)=131072]
 

Which happens due to large document which has many destination names in it.

Notice that changing dest_names_size in texmf.cnf has no effect on the above as lualatex uses sup_dest_names_size for the limit of destination names and not dest_names_size which is used it seems by pdflatex only. Thanks to Marcel Krüger for this hint and pointing this out.

The solution I did is to download lualatex sources from https://github.com/TeX-Live/luatex and extract into a temporary folder. The exact file to download from above is the zip file https://github.com/TeX-Live/luatex/archive/refs/heads/trunk.zip which shows up when clicking on the pull down menu called code and then download zip. You can use the command

wget https://github.com/TeX-Live/luatex/archive/refs/heads/trunk.zip to download the zip file directly to some TMP folder and then extract the zip file. This will create new folder called luatex-trunk.

Edit the file pdfdest.h in the source tree inside. It is located in

>pwd 
/home/me/TMP/luatex-trunk/source/texk/web2c/luatexdir/pdf 
>ls -lrt pdfdest.h 
-rw-r--r-- 1 me me 2167 May 27 18:12 pdfdest.h
 

There you will find the following lines

# define inf_dest_names_size 1000 /* min size of the destination names table for PDF output */ 
# define sup_dest_names_size 131072 /* max size of the destination names table for
 

I changed sup_dest_names_size which is now \(2^{17}\) to \(2^{18}=262144\). Saved the file.

Now at the top level folder where you extracted lualatex, there is a file called build.sh

>pwd 
/home/me/TMP/luatex-trunk 
>ls -l build.sh 
-rwxr-xr-x 1 me me 11900 May 27 18:12 build.sh
 

Edit the above file and change BUILDLUAHB=FALSE to BUILDLUAHB=TRUE This is so it builds luahbtex in addition to luatex. Also make sure to uncomment the lines

#export CFLAGS="-D_FORTIFY_SOURCE=2 -O3" 
#export CXXFLAGS="-D_FORTIFY_SOURCE=2 -O3"
 

By removing the # from the front to now look like this.

export CFLAGS="-D_FORTIFY_SOURCE=2 -O3" 
export CXXFLAGS="-D_FORTIFY_SOURCE=2 -O3"
 

This is important, else the generated binaries will run very slow.

Now type ./build.sh

When done there will be two binaries luahbtex and luatex in folder

>pwd 
/home/me/TMP/luatex-trunk/build/texk/web2c 
-rwxr-xr-x  1 me me 7960728 Jul  7 20:42 luatex 
-rwxr-xr-x  1 me me 9376072 Jul  7 20:42 luahbtex
 

This completes the first phase. The second phase is to copy the above files (as root) from the above folder to your texLive installation.

On my system linux ubuntu I became root and copied the above 2 files to /usr/local/texlive/2022/bin/x86_64-linux/ overwriting the original files (made a backup copy before doing this just in case)

Now the final step is to rebuild texmf files using the command

sudo -E env "PATH=$PATH" fmtutil-sys --all
 

Make sure to run it as above using root! as shown above. Do not do

#DO NOT DO THIS, USE THE ABOVE INSTEAD 
sudo fmtutil-sys --all
 

As this might fail if root does not know where your TL path is and this can cause problems. (This happened to me).

That is all. Now lualatex will have its destination names set at 262144 instead of 131072 hardcoded into the source code.

Future versions of Lualatex should really make this parameter available to users to modify without having to do this each time but I asked the lualatex mailing list to do this and was just ignored.

https://www.mail-archive.com/luatex@tug.org/msg07512.html

I guess no body cares about generating large documents so it does not affect others.

May be in the future this can be changed using /usr/local/texlive/2022/texmf.cnf

Note: During doing this, I was getting an error

>lualatex foo.tex 
This is LuaHBTeX, Version 1.13.2 (TeX Live 2021) 
 restricted system commands enabled. 
 
(Fatal format file error; I'm stymied)>
 

If you get such an error, It turned out there was a hidden folder called $HOME/.texlive2022 in my home folder. Simply deleting this folder and trying again the texmf command above solved this problem.

It seems newer versions of TL creates this hidden folder which I never knew about.

Now your document can have up to 262144 destination names available instead of the current low value.

3.3 How to install garamond fonts

THis was complicated., so I wrote the what I did below. In the latex file use this. THis is all on a Linux system. I am using lualatex and not pdflatex.

... 
\usepackage[T1]{fontenc} 
\usepackage[urw-garamond]{mathdesign} 
....
 

But just typing lualatex foo.tex gives this erorr

! error:  (type 1): cannot open file for reading 'ugmm8a.pfb'

These fonts do not come with tex live. So the following instructions shows what to do to get them.

On a terminal, typed, from some empty folder

wget https://tug.org/fonts/getnonfreefonts/install-getnonfreefonts
 

This downloaded install-getnonfreefonts in the folder.

Next, typed sudo "PATH=$PATH"  ./install-getnonfreefonts --sys --all

and the result is

Detected System: x86_64-linux 
Detected Installation: /usr/local/texlive/2018 
mkdir /usr/local/texlive/2018/texmf-dist/scripts/getnonfreefonts ...     [done] 
Installing texmf-dist/scripts/getnonfreefonts/getnonfreefonts.pl ...     [done] 
Installing texmf-dist/doc/man/man1/getnonfreefonts.1 ...                 [done] 
Installing texmf-dist/doc/man/man1/getnonfreefonts.man1.pdf ...          [done] 
md5sum: a9e772165e8fdb620bcf9c75c17facda getnonfreefonts.pl ...            [ok] 
md5sum: 49be4444054d85b6037d237552a7cea1 getnonfreefonts.1 ...             [ok] 
md5sum: f825d523d686dbecdc787535b40f09d0 getnonfreefonts.man1.pdf ...      [ok] 
Fixing File Permissions ...                                              [done] 
Creating symlink in 'bin/x86_64-linux' ...                               [done] 
mktexlsr: Updating /usr/local/texlive/2018/texmf-dist/ls-R... 
mktexlsr: Done.
 

Next, typed

sudo "PATH=$PATH" /usr/local/texlive/2018/bin/x86_64-linux/getnonfreefonts --sys  garamond
 

and it said

--2018-09-20 16:26:21--  https://www.tug.org/~kotucha/getnonfreefonts/getfont.pl 
Resolving www.tug.org (www.tug.org)... 91.121.174.77 
Connecting to www.tug.org (www.tug.org)|91.121.174.77|:443... connected. 
HTTP request sent, awaiting response... 200 OK 
Length: 33001 (32K) 
Saving to: getfont.pl 
 
getfont.pl                            100%[=======================================================================>]  32.23K  --.-KB/s    in 0.1s 
 
2018-09-20 16:26:22 (296 KB/s) - getfont.pl saved [33001/33001] 
------------------------------------------------------ 
Installation directory: /usr/local/texlive/texmf-local 
------------------------------------------------------ 
=================== 
Package 'garamond': 
=================== 
 
Downloading 'http://mirrors.ctan.org/fonts/urw/garamond.zip' 
--2018-09-20 16:26:22--  http://mirrors.ctan.org/fonts/urw/garamond.zip 
Resolving mirrors.ctan.org (mirrors.ctan.org)... 2a01:488:67:1000:b01c:36b8:0:1, 176.28.54.184 
Connecting to mirrors.ctan.org (mirrors.ctan.org)|2a01:488:67:1000:b01c:36b8:0:1|:80... connected. 
HTTP request sent, awaiting response... 302 Found 
Location: http://mirror.las.iastate.edu/tex-archive/fonts/urw/garamond.zip [following] 
--2018-09-20 16:26:30--  http://mirror.las.iastate.edu/tex-archive/fonts/urw/garamond.zip 
Resolving mirror.las.iastate.edu (mirror.las.iastate.edu)... 129.186.138.51 
Connecting to mirror.las.iastate.edu (mirror.las.iastate.edu)|129.186.138.51|:80... connected. 
HTTP request sent, awaiting response... 200 OK 
Length: 393158 (384K) [application/zip] 
Saving to: garamond.zip 
 
garamond.zip                          100%[=======================================================================>] 383.94K   708KB/s    in 0.5s 
 
2018-09-20 16:26:36 (708 KB/s) - garamond.zip saved [393158/393158] 
 
                                                                [download done] 
Checking integrity of file 'garamond.zip'...                               [ok] 
 
a60beaf12c12c69eeb8fdc82bd481949  garamond.zip                      [MD5sum ok] 
 
Extracting 'ugm.zip' from 'garamond.zip'...                              [done] 
Extracting 'ugm.zip'...                                                  [done] 
Extracting 'garamond.zip'...                                             [done] 
Installing 'ugm.map'...updmap [WARNING]: resetting $HOME value (was /home/me) to root's actual home (/root). 
Creating new config file /usr/local/texlive/2018/texmf-config/web2c/updmap.cfg 
                                                  [done] 
Running 'mktexlsr /usr/local/texlive/texmf-local >/dev/null 2>/dev/null' ... [done] 
 
Updating map files (updmap-sys). Be patient...updmap [WARNING]: resetting $HOME value (was /home/me) to root's actual home (/root). 
                           [done]
 

Finally, now I can compile the latex file using lualatex foo.tex with the above packages, and not get the error showed at earlier above.

These look like nice fonts.

3.4 How to draw faces in Latex

Found this on the net. I wonder how many such faces can one draw in Latex?

\widehat{\dbinom{\odot_{\text{v}}\odot}{\wr}} gives

\(\widehat {\dbinom {\odot _{\text {v}}\odot }{\wr }}\)

3.5 How to see more context where the erorr generated came from?

Add \errorcontextlines=200 in preamble, that will display more lines around where the error shows. (thanks to Ulrike Fischer)

3.6 How to include image in landscape mode?

\documentclass[11pt]{article}% 
\usepackage{graphicx} 
\usepackage{rotating} 
\begin{document} 
 
\begin{sidewaysfigure}[!htbp] 
\includegraphics[width=1\textwidth]{image} 
\end{sidewaysfigure} 
 
\end{document}
 

3.7 How to spell check Latex document?

aspell -t -c file.tex

3.8 How to obtain external file information about Latex build

  1. use \RequirePackage{snapshot} see http://tex.stackexchange.com/questions/24542/create-list-of-all-external-files-used-by-master-latex-document
  2. use \listfiles
  3. use lualatex -recorder foo.tex it should create foo.fls

3.9 How to use minted

First install this

sudo apt-get install python-pygments
 

The above installed old version 1.6, so next I tried this

sudo pip install --upgrade pygments
 

Anow the version is 2.1.3

Then call pdflatex like this

pdflatex --shell-escape foo.tex
 

Where foo.tex is

\documentclass[11pt]{article}%ext 
\usepackage[T1]{fontenc} 
\usepackage[utf8]{inputenc} %DO NOT USE WIT LUALATEX, only with pdflatex 
\usepackage[tracking,protrusion=true,expansion=true]{microtype} 
\usepackage[margin=1in]{geometry} 
 
\usepackage{minted} 
\usepackage{upquote} %to fix string quotes 
 
\begin{document} 
\begin{minted}[mathescape,linenos=true,fontfamily=tt,fontsize=\normalsize] 
                {matlab} 
clear all; close all; 
t   = 0:0.05:50; 
s   = tf('s'); 
sys = 1/(s^2+0.2*s+1); 
y   = step(sys,t); 
plot(t,y,'-r') 
hold on 
y  = impulse(sys,t); 
plot(t,y,'-k') 
title('Step and Impulse responses'); 
xlabel('t'); 
ylabel('y(t)'); 
xlim([0 50]); 
ylim([-0.8 2]); 
legend('step','impulse'); 
grid on; 
set(gcf,'Position',[10,10,310,310]); 
\end{minted} 
\end{document}
 

To compile with tex4ht do this

htlatex foo.tex "" "" "" -shell-escape

To compile with make4ht do make4ht foo.tex "--shell-escape"

3.10 How to increase memory for Latex?

sudo vi /usr/local/texlive/2015/texmf.cnf
 

Added these:

% (Public domain.) 
% This texmf.cnf file should contain only your personal changes from the 
% original texmf.cnf (for example, as chosen in the installer). 
% 
% That is, if you need to make changes to texmf.cnf, put your custom 
% settings in this file, which is .../texlive/YYYY/texmf.cnf, rather than 
% the distributed file (which is .../texlive/YYYY/texmf-dist/web2c/texmf.cnf). 
% And include *only* your changed values, not a copy of the whole thing! 
% 
 
buf_size=9000000 
pool_size=9000000 
main_memory=8000000 
save_size=1000000 
max_strings = 5000000 
strings_free = 1000000 
hash_extra=10000000 
stack_size=500000
                                                                                    
                                                                                    
 

Then run

sudo -E env "PATH=$PATH" fmtutil-sys --all
 

3.11 How to use Maple style sheets (packages) with texlive?

I have $HOME/texmf and so did these steps

cd $HOME/texmf/tex/latex 
mkdir maple 
cd maple 
cp C:\Program Files\Maple 18\etc\*.sty .  %I use Vbox 
 
in other words 
 
cp /maple_location/etc/*.sty .  %copy all style files over
 

If using miketex, then use the GUI, add ROOT, and click apply.

3.12 How to install and use pdf2htmlEX?

To install

sudo apt-get update 
sudo apt-get install pdf2htmlex
 

To use

pdf2htmlEX --zoom 1.3 HW2_solution.pdf
 

To remove the side-bar which has extra TOC do

pdf2htmlEX --zoom 1.3 --embed-outline 0  foo.pdf
 

pdf2htmlEX seems to use html as extension. no option to change it so use this to make it use .htm which is what I use

pdf2htmlEX --zoom 1.3 --embed-outline 0  foo.pdf > foo.htm
 

One thing that I still do not understand about this program. It converts the whole pdf file to html page. Ok. But then what is the difference between this and using the build-in pdf reader in a browser, such as with Chrome for example?

I could not find how to make it split pages by sections and chapters and such as I can do with tex4ht. Without this ability, I am not sure how useful this will be for me. It is just like using the pdf itself this way. Will try to find out about this.

3.13 How to put image in a title page?

\documentclass[oneside,a4paper  , 12 pt]{book} 
\usepackage{titlepic} 
\usepackage{graphicx} 
\usepackage{caption} 
%\usepackage{package} 
%\usepackage[space]{grffile} 
 
\begin{document} 
\title{my book} 
\author{me} 
\date{\today} 
\titlepic{ 
\begin{figure}[t!] 
\centering 
\includegraphics[width=0.7\linewidth]{img.png} 
\caption{} 
\label{fig:img} 
\end{figure} 
} 
\maketitle 
 
test 
 
\end{document}
 
pict

3.14 How to convert pdf to eps?

See http://tex.stackexchange.com/questions/20883/how-to-convert-pdf-to-eps This inkscape input.pdf --export-eps=output.eps works ok, but the above command gives errors such as these on some images:

>inkscape 3d_1.pdf --export-eps=3d_1.eps 
** Message: Invalid glyph found, continuing... 
** Message: Invalid glyph found, continuing... 
** Message: Invalid glyph found, continuing... 
** Message: Invalid glyph found, continuing... 
** Message: Invalid glyph found, continuing... 
** Message: Invalid glyph found, continuing... 
** Message: Invalid glyph found, continuing... 
** Message: Invalid glyph found, continuing...
 

While on the same file, pdf2eps below works fine.

To crop pdf also (which can be useful) use this script by Herbert from above link

#!/bin/sh 
# $Id: pdf2eps,v 0.01 2005/10/28 00:55:46 Herbert Voss Exp $ 
# Convert PDF to encapsulated PostScript. 
# usage: 
# pdf2eps <page number> <pdf file without ext> 
 
pdfcrop $2.pdf 
pdftops -f $1 -l $1 -eps "$2-crop.pdf" 
rm  "$2-crop.pdf" 
mv  "$2-crop.eps" $2.eps
 

I wrote the following simple script prep which process all the pdf image files and generates the needed files for tex4ht.

#!/bin/bash 
for file in $1; do 
    filename=${file%.*} 
    pdf2svg "$filename.pdf" "$filename.svg" 
    pdf2eps 1 "$filename" 
done
 

It is called like this prep "*.pdf" or for one file prep foo.pdf it will generate a .svg and .eps for each file.

3.15 How to draw a baseline hairline for an equation?

This is thanks to @egreg from Tex stackexchange:

\newcommand{\rl}{\rlap{\vrule height 0pt depth .1pt width \textwidth}}
 

and then use \rl in the left hand sides of the equations.

3.16 How to find what changed in TexLive?

see http://tex.stackexchange.com/questions/156908/whats-new-on-tlmgr one good method is by egreg which is this command http://tug.org/svn/texlive/trunk/Master/texmf-dist/tex/latex/?sortby=date

3.17 extracting selected pages from a pdf?

To extract selected pages from a pdf into a separate pdf see http://www.linuxjournal.com/content/tech-tip-extract-pages-pdf

Use pdftk (free install on linux, use package manager). Here is an example

pdftk A=myfile.pdf cat A6-10 output result.pdf
 

3.18 how to include files in Latex

see http://tex.stackexchange.com/questions/246/when-should-i-use-input-vs-include

3.19 combining complete documents into one

3.19.1 combining using manual sectioning

Problem description: I have many standalone Latex documents that I want to compile into documents on their own, but also I want to combine them into one main document and have the table of contents and other references work as if all documents were written as one file.

Solution:

Given this example layout

 home/main.tex 
 home/folderA/a.tex
 

Where main.tex and a.tex are self contained Latex files, each with its own title, table of contents and can include local resources such as images and listings.

Add the package \usepackage{standalone} in main.tex to strip all the preamble from the included latex files. Also add it to each child document, so that each child document can be compiled as standalone as well.

To use the above, make sure the master document at the top level includes all packages included by all the children.

Setup main.tex

\documentclass[12pt,notitlepage]{article} 
\usepackage{standalone}% 
\usepackage{listings} 
\usepackage{import} 
\usepackage{lipsum} 
\usepackage{graphicx} 
\usepackage{hyperref} 
 
\makeatletter 
\providecommand{\currentimportpath}{\import@path} 
\makeatother 
 
\begin{document} 
\title{This is my document home/main.tex title} 
\author{me} 
\maketitle 
\tableofcontents 
 
\section{this is first section in main.tex} 
once upon a time, and now include the other document 
 
\subimport{folderA/}{a} 
\end{document}
 

Setup a.tex as follows. This is important: remember to add \standalonetrue after \usepackage{standalone} in each child package. We need this to be able to compile each child package on its own and get a table of contents and title. We will us an \ifstandalone logic in each child to check if we are building it standalone or not. When the main is build, this flag will automatically be false, hence we will not get table of content shown in each child. Little complicated, but just do it as shown:

\documentclass[12pt,notitlepage]{article} 
\usepackage{standalone} 
\standalonetrue   %remember this ! 
 
\usepackage{listings} 
\usepackage{import} 
\usepackage{lipsum} 
\usepackage{graphicx} 
\usepackage{hyperref} 
 
\makeatletter 
\providecommand{\currentimportpath}{\import@path} 
\makeatother 
 
\begin{document} 
 
\ifstandalone   %Do this, so toc only shows when build standalone 
  \title{This is my document home/folderA/a.tex title} 
  \author{me} 
  \maketitle 
  \tableofcontents 
\fi 
 
\section{first section in file a.tex} 
\includegraphics{a.png} 
 
\section{second section in file a.tex} 
\lstinputlisting{a.txt} 
 
\section{third section in file a.tex} 
you can find my report \href{\currentimportpath a.txt}{here} 
 
\lipsum[1] 
\end{document}
 

pict

Now you can compile a.texm or its own

cd home/folderA 
pdflatex a.tex
 

And the result is

pict

But when compiling main.tex cd home; pdflatex main.tex the result shows a table of contents that includes all children documents as shown

pict

This is the result side by side

pict

This zip file contains the tree shown above with all the files needed to rebuild it.

3.19.2 combining using automatic sectioning

One problem with the above approach, is that we had to be explicit with add \section and \subsection in the correct order in different documents in different folders.

It would be better if this can be automated. Using a method shown here http://tex.stackexchange.com/questions/9024/is-there-a-program-t hat-allows-to-move-sections-and-automatically-adjusts-the-le and I modified it slightly, here are the files needed. First assume we have a tree like this:

home/main.tex 
home/A/a.tex 
home/A/B/b.tex
 

and we want to build main.tex, which includes a.tex, and where a.tex also includes b.tex, and where we can build each document as standalone. These are the 3 files

main.tex

\documentclass[12pt,notitlepage]{book} 
\usepackage{standalone}% 
\input{commonlatex} 
 
\begin{document} 
\title{This is my document home/main.tex title} 
\author{me} 
\maketitle 
\tableofcontents 
 
\begin{deeplevel}{this is first section in main.tex} 
once upone a time, and now include the other document 
 
\subimport*{folderA/}{a} 
\end{deeplevel} 
\end{document}
                                                                                    
                                                                                    
 

the file a.tex is

\documentclass[12pt,notitlepage]{article} 
\usepackage{standalone} 
\standalonetrue 
\input{commonlatex} 
 
\begin{document} 
 
\ifstandalone 
  \setcounter{level@depth}{1} 
  \title{This is my document home/folderA/a.tex title} 
  \author{me} 
  \maketitle 
  \tableofcontents 
\fi 
 
\begin{deeplevel}{first section in file a.tex} 
\includegraphics{a.png} 
 
  \subimport*{folderAB/}{b} 
 
  \begin{deeplevel}{this should show up below the above} 
     \lipsum[75] 
  \end{deeplevel} 
 
\end{deeplevel} 
 
\begin{deeplevel}{second section in file a.tex} 
\lstinputlisting{a.txt} 
\end{deeplevel} 
 
\begin{deeplevel}{third section in file a.tex} 
you can find my report \href{\currentimportpath a.txt}{here} 
\end{deeplevel} 
 
\lipsum[1] 
\end{document}
 

and the file b.tex is

\documentclass[12pt,notitlepage]{article} 
\usepackage{standalone} 
\standalonetrue 
\input{commonlatex} 
 
\begin{document} 
 
\ifstandalone 
  \setcounter{level@depth}{2} 
  \title{This is my document home/folderA/folderB/b.tex title} 
  \author{me} 
  \maketitle 
  \tableofcontents 
\fi 
 
\begin{deeplevel}{first section in file b.tex} 
\lipsum[75] 
 
\begin{deeplevel}{this should show up below the above} 
  \lipsum[75] 
\end{deeplevel} 
 
\end{deeplevel} 
 
\begin{deeplevel}{second section in file b.tex} 
\lstinputlisting{b.txt} 
\end{deeplevel} 
 
 
\begin{deeplevel}{third section in file b.tex} 
you can find my report \href{\currentimportpath b.txt}{here} 
\end{deeplevel} 
 
\lipsum[1] 
\end{document}
 

and the common include file is

%====================================== 
\makeatletter 
\newcounter{level@depth} 
\setcounter{level@depth}{-1} 
 
\newenvironment{deeplevel} % 
{ % 
  \addtocounter{level@depth}{1}% 
 
  \ifcase\c@level@depth 
  \expandafter \part 
  \or \expandafter \chapter 
  \or \expandafter \section 
  \or \expandafter \subsection 
  \or \expandafter \subsubsection 
  \or \expandafter \paragraph 
  \or \expandafter \subparagraph 
  \or \expandafter \subsubparagraph 
  \else 
  \PackageError{deeplevel} 
  { % 
    Sections are too deeply nested.% 
  } % 
  { % 
    Trying to recover with \string\subsubparagraph% 
  } % 
  \expandafter \subsubparagraph 
  \fi 
} % 
{% 
  \addtocounter{level@depth}{-1}% 
} 
 
\makeatother
 

Now one is able to build main.tex or a.tex or b.tex each on its own, and still get a complete document for each.

3.20 how to install lyx on Linux

see http://wiki.lyx.org/LyX/LyXOnUbuntu

if not in the package manager PPA, then do

sudo add-apt-repository ppa:lyx-devel/daily (add the PPA) 
sudo apt-get update (update so that apt is aware of the new PPA) 
sudo apt-get install lyx2.0 (install from the PPA) 
lyx2.0 &
 

http://biosun1.harvard.edu/~paciorek

More info on pdf hyper-references is at http://www.tug.org/applications/hyperref/manual.html.

3.22 page breaks

reference: http://help-csli.stanford.edu/tex/latex-pagebreaks.shtml

 
\pagebreak[] 
 use to start a new page at the end of the current line. Without 
 arguments if forces a page break. With arguments of 0,1,2,3, 
 or 4 it suggests that this is a good place to break. 4 being 
 equivalent to no argument and forcing the break. No extra space 
 is put at the end of the page. 
\nopagebreak 
 similar to \pagebreak except it prevents a pagebreak at the end 
 of the current line. I rarely use it. 
\samepage 
 pretty much as the latex manual says. I rarely use it. 
\newpage 
 forces a break at the point and puts in space as needed at the 
 end of the page. 
\clearpage 
    similar to \newpage but figures are also printed 
\cleardoublepage 
    similar to \clearpage but will force another page if needed so 
    the next page with print is odd numbered.
 

3.23 using tables

From http://www.andy-roberts.net/writing/latex/tables

 
The tabular is another such environment, designed for formatting your data into 
nicely arranged tables. Arguments are required after the environment declaration to 
describe the alignment of each column. The number of columns does not need to 
be specified as it is inferred by looking at the number of arguments provided. 
It is also possible to add vertical lines between the columns here. 
 
The following symbols are available to describe the table columns: 
l       left-justified column 
c       centered column 
r       right-justified column 
p{width}        paragraph column with text vertically aligned at the top 
m{width}        paragraph column with text vertically aligned in the middle 
b{width}        paragraph column with text vertically aligned at the bottom 
|       vertical line 
||      double vertical line 
 
Once in the environment, 
&       column separator 
\\      start new row 
\hline  horizontal line 
 
to adjust the spacing between rows in a latex table, add square 
brackets and the size adjustment after the linebreak. 
 
for instance, to compress rows by 1 inch: 
 
    entry1 & entry2 & entry3 \\[-1in]
 

3.24 passing flag from command line to pdflatex and htlatex?

for htlatex

htlatex main.tex "" "" ""  "\def\flag{}"
 

for pdflatex

pdflatex "\def\flag{}\input{main.tex}"
 

and now inside main.tex write

\documentclass{article} 
\begin{document} 
\ifdefined\flag 
  yes 
\else 
 no 
\fi 
\end{document}
 

3.25 What levels are there? TOC configuration

from http://www.emerson.emory.edu/services/latex/latex_132.html

Sectioning commands provide the means to structure your text into units.

\part 
\chapter (report style only) 
\section 
\subsection 
\subsubsection 
\paragraph 
\subparagraph 
\subsubparagraph (milstd and book-form styles only) 
\subsubsubparagraph (milstd and book-form styles only)
 
 \part  -1    -----> school 
 \chapter  0  ------> semester 
 \section  1  ------> course 
 \subsection  2  -------> HWs 
 \subsubsection  3 ----> HW1,2,3.... 
 \paragraph  4   --------> part(a),(b),..... 
 \subparagraph  5
 

\setcounter{tocdepth}{n} where n is an integer, tells latex how deep to make TOC. n depends on the class type, see above.

\setcounter{secnumdepth}{m} tells latex which entries in the TOC (which depends on the first command above) to give it a number to the left side. default is 3 I think. But better to have numbers for all sections and subsection in TOC.

Do the above in preamble of document.

some links on TOC in latex

  1. http://www.andy-roberts.net/writing/latex/contents
  2. http://help-csli.stanford.edu/tex/latex-sections.shtml
  3. http://facweb.knowlton.ohio-state.edu/pviton/support/swphtpa4.html
  4. To make paragraph make new entry in TOC below subsubsection, see this

can change depth of toc using  \setcounter{tocdepth}{depth} in preamble. it looks like default depth is 3.

3.27 on fonts

using Fourier fonts

  \usepackage{fourier} 
  \usepackage[T1]{fontenc}
 

may be need to install. I got error

! LaTeX Error: File `fourier.sty' not found.
 

remember the $ texhash command also.

try downloading it from http://www.ctan.org/pkg/fourier but I’ll wait until Tex Live 2013 is out. There are more steps to do to install it it seems.

3.28 pixels and Latex

From David Carlisle

 40px is a variable size depending on screen resolution, 
if you take a nominal 76 dpi then it's 40/76 on 1in.
 

3.29 on equations

Need to work on this.

3.29.1 using align with references

see http://www.dickimaw-books.com

This image below from the above page http://www.dickimaw-books.com/latex/novices/html/align.html

pict

3.30 How to upgrade latex once installed?

see http://tex.stackexchange.com/questions/55437/how-do-i-update-my-tex-distribution

Basically, just do

sudo /usr/local/texlive/2014/bin/i386-linux/tlmgr  update --self 
sudo /usr/local/texlive/2014/bin/i386-linux/tlmgr update --all
 

For TL 2015

sudo /usr/local/texlive/2015/bin/x86_64-linux/tlmgr  update --self 
sudo /usr/local/texlive/2015/bin/x86_64-linux/tlmgr update --all
 

3.31 Things to do post Installation of texlive 2016 on Linux

These are the steps I need to do after installation of TL

  1. fix \pgfusepathqfill bug. See http://tex.stackexchange.com/questions/185349/error-using-pgfsysdriver-with-tex4ht-only-shows-up-with-texlive-2014-ok-with-t
  2. There is a new error when compiling make4ht --lua see http://tex.stackexchange.com/questions/315162/error-with-tex4ht-under-tl-2016-when-using-lua-string-contains-an-invalid-utf-8 but this should be fixed very soon (ok, allready fixed)
  3. If compiling with lualtaex, need to add this to all files

    \IfFileExists{luatex85.sty} 
    { 
    \usepackage{luatex85} 
    } 
    {}
  4. Watch out, do not use \usepackage[T1]{fontenc} Makes tex4ht \verb not accept different fonts. Bug. see http://tex.stackexchange.com/questions/318232/why-tex4ht-do-not-change-font-size-of-verb-when-including-usepackaget1font
  5. Increase bufsize, else it will fail on some large builds

    sudo vi /usr/local/texlive/2016/texmf.cnf
     
    

    Added these:

    % (Public domain.) 
    % This texmf.cnf file should contain only your personal changes from the 
    % original texmf.cnf (for example, as chosen in the installer). 
    % 
    % That is, if you need to make changes to texmf.cnf, put your custom 
    % settings in this file, which is .../texlive/YYYY/texmf.cnf, rather than 
    % the distributed file (which is .../texlive/YYYY/texmf-dist/web2c/texmf.cnf). 
    % And include *only* your changed values, not a copy of the whole thing! 
    % 
     
    buf_size=90000000 
    pool_size=9000000 
    main_memory=8000000 
    save_size=1000000
     
    
  6. increase open file limit, lualatex still has problem

    edit the file /etc/security/limits.conf as root and add these lines

    * soft nofile 4096 
    * hard nofile 4096
     
    
  7. install pdf2svg sudo apt-get install pdf2svg
  8. install scour (do not use apt-get install scour, use pip to get latest version)

    sudo apt-get install python-pip 
    sudo pip install scour 
     
    Downloading/unpacking scour 
      Downloading scour-0.33.tar.gz 
      Running setup.py (path:/tmp/pip_build_root/scour/setup.py) egg_info for package scour 
     
    Downloading/unpacking six>=1.9.0 (from scour) 
      Downloading six-1.10.0-py2.py3-none-any.whl 
    Installing collected packages: scour, six 
      Running setup.py install for scour 
     
        Installing scour script to /usr/local/bin 
      Found existing installation: six 1.5.2 
        Not uninstalling six at /usr/lib/python2.7/dist-packages, owned by OS 
    Successfully installed scour six 
    Cleaning up... 
     
    >which scour 
    /usr/local/bin/scour 
     
    >scour --version 
    0.33
     
    

    used to shrink size of svg images (clean them)

  9. fix algorithm2e.sty so that lualatex can use

    styles>kpsewhich  algorithm2e.sty 
    /usr/local/texlive/2016/texmf-dist/tex/latex/algorithm2e/algorithm2e.sty
     
    

    and remove 2 lines with non-ascii chars, around lines 1313 and 1315.

  10. Make sure not to use subimport* but use \subimport
  11. install sudo apt-get install imagemagick for convert command
  12. install  sudo apt-get install optipng to optimize png

3.32 Installation of texlive 2015 on Linux

Download the .gz file from https://www.tug.org/texlive/acquire-netinstall.html

install-tl-unx.tar.gz

Then extract

gunzip install-tl-unx.tar.gz 
tar -xvf install-tl-unx.tar
 

Then move to the folder created from the above and do

sudo ./install-tl
 

Make sure to change the paper type to letter. The default is A4.

======================> TeX Live installation procedure <===================== 
 
======>   Letters/digits in <angle brackets> indicate   <======= 
======>   menu items for commands or options            <======= 
 
 Detected platform: GNU/Linux on Intel x86 
 
 <B> binary platforms: 1 out of 19 
 
 <S> set installation scheme (scheme-full) 
 
 <C> customizing installation collections 
     47 collections out of 48, disk space required: 4061 MB 
 
 <D> directories: 
   TEXDIR (the main TeX directory): 
     /usr/local/texlive/2015 
   TEXMFLOCAL (directory for site-wide local files): 
     /usr/local/texlive/texmf-local 
   TEXMFSYSVAR (directory for variable and automatically generated data): 
     /usr/local/texlive/2015/texmf-var 
   TEXMFSYSCONFIG (directory for local config): 
     /usr/local/texlive/2015/texmf-config 
   TEXMFVAR (personal directory for variable and automatically generated data): 
     ~/.texlive2015/texmf-var 
   TEXMFCONFIG (personal directory for local config): 
     ~/.texlive2015/texmf-config 
   TEXMFHOME (directory for user-specific files): 
     ~/texmf 
 
 <O> options: 
   [ ] use letter size instead of A4 by default 
   [X] allow execution of restricted list of programs via \write18 
   [X] create all format files 
   [X] install macro/font doc tree 
   [X] install macro/font source tree 
   [ ] create symlinks to standard directories 
 
 <V> set up for portable installation 
 
Actions: 
 <I> start installation to hard disk 
 <H> help 
 <Q> quit
 

Enter O and then

Options setup: 
 
 <P> use letter size instead of A4 by default: [X] 
 <E> execution of restricted list of programs: [X] 
 <F> create format files:                      [X] 
 <D> install font/macro doc tree:              [X] 
 <S> install font/macro source tree:           [X] 
 <L> create symlinks in standard directories:  [ ] 
            binaries to: 
            manpages to: 
                info to: 
 
Actions: (disk space required: 4061 MB) 
 <R> return to main menu 
 <Q> quit 
 
Enter command: R
 

I do not know what create symlinks in standard directories is supposed to be set to so leave it blank and add path in your .bashrc to the latex bin folder

Enter command: I 
Installing to: /usr/local/texlive/2015 
Installing [0001/3068, time/total: ??:??/??:??]: 12many [376k] 
Installing [0002/3068, time/total: 00:07/09:58:59]: 2up [66k] 
Installing [0003/3068, time/total: 00:08/09:43:10]: Asana-Math [482k] 
Installing [0004/3068, time/total: 00:17/09:51:45]: ESIEEcv [137k] 
Installing [0005/3068, time/total: 00:20/10:06:31]: FAQ-en [4971k] 
Installing [0006/3068, time/total: 01:55/10:12:15]: GS1 [1100k] 
Installing [0007/3068, time/total: 02:15/10:07:53]: HA-prosper [266k] 
Installing [0008/3068, time/total: 02:20/10:07:44]: IEEEconf [188k] 
Installing [0009/3068, time/total: 02:24/10:09:36]: IEEEtran [1355k] 
Installing [0010/3068, time/total: 02:49/10:07:00]: MemoirChapStyles [739k] 
Installing [0011/3068, time/total: 03:03/10:07:07]: SIstyle [338k] 
Installing [0012/3068, time/total: 03:10/10:09:07]: SIunits [284k] 
Installing [0013/3068, time/total: 03:15/10:07:54]: Tabbing [217k] 
Installing [0014/3068, time/total: 03:20/10:10:39]: Type1fonts [516k] 
Installing [0015/3068, time/total: 03:30/10:11:13]: a0poster [119k] 
Installing [0016/3068, time/total: 03:32/10:10:28]: a2ping [48k] 
Installing [0017/3068, time/total: 03:33/10:10:45]: a2ping.i386-linux [1k] 
Installing [0018/3068, time/total: 03:33/10:10:44]: a4wide [133k] 
Installing [0019/3068, time/total: 03:35/10:09:15]: a5comb [91k] 
Installing [0020/3068, time/total: 03:37/10:10:03]: aastex [1292k] 
Installing [0021/3068, time/total: 04:05/10:18:46]: abbr [4k] 
Installing [0022/3068, time/total: 04:05/10:18:36]: abc [156k] 
Installing [0023/3068, time/total: 04:09/10:21:06]: abntex2 [4493k] 
..... 
running fmtutil-sys --no-error-if-no-engine=luajittex --all ...done 
running package-specific postactions 
finished with package-specific postactions 
 
 See 
   /usr/local/texlive/2015/index.html 
 for links to documentation.  The TeX Live web site 
 contains updates and corrections: http://tug.org/texlive. 
 
 TeX Live is a joint project of the TeX user groups around the world; 
 please consider supporting it by joining the group best for you. The 
 list of user groups is on the web at http://tug.org/usergroups.html. 
 
 Add /usr/local/texlive/2015/texmf-dist/doc/info to INFOPATH. 
 Add /usr/local/texlive/2015/texmf-dist/doc/man to MANPATH 
   (if not dynamically found). 
 
 Most importantly, add /usr/local/texlive/2015/bin/i386-linux 
 to your PATH for current and future sessions. 
 
 Welcome to TeX Live! 
Logfile: /usr/local/texlive/2015/install-tl.log 
>
 

Now install make4ht. Make sure it goes to ~/texmf/scripts/lua/make4ht and to set the path to point to the above as well.

No need to install lua as it comes with TL

Make sure to fix the pgfsysdriver to be able to use tikz, see this

3.33 Installation of texlive 2014 on Linux

Download the .gz file from http://ctan.math.washington.edu/tex-archive/systems/texlive/tlnet/

install-tl-unx.tar.gz 16-Jun-2014 18:26  3.2M

Then extract

gunzip install-tl-unx.tar.gz 
tar -xvf install-tl-unx.tar
 

Then move to the folder created from the above and do

sudo ./install-tl 
 
Make sure to change the paper type to letter. The default is 
A4. 
 
Enter command: I 
Installing to: /usr/local/texlive/2014 
.... 
TeX Live is a joint project of the TeX user groups around the world; 
 please consider supporting it by joining the group best for you. The 
 list of user groups is on the web at http://tug.org/usergroups.html. 
 
 
 Add /usr/local/texlive/2014/texmf-dist/doc/info to INFOPATH. 
 Add /usr/local/texlive/2014/texmf-dist/doc/man to MANPATH 
   (if not dynamically found). 
 
 Most importantly, add /usr/local/texlive/2014/bin/i386-linux 
 to your PATH for current and future sessions. 
 
 Welcome to TeX Live! 
 
 Summary of warning messages during installation: 
   Partial download of http://mirror.jmu.edu/pub/CTAN/systems/texlive/tlnet/archive/chletter.doc.tar.xz found, removing it. 
 
Logfile: /usr/local/texlive/2014/install-tl.log 
>

3.33.1 post installation for tex4ht issues

I need to fix/add few things after texlive is installed for tex4ht. This is a summary of the items to do.

  1. When using standalone package, this error will show up with tex4ht only

    (/usr/local/texlive/2014/texmf-dist/tex/generic/xkeyval/xkeyval.tex 
    (/usr/local/texlive/2014/texmf-dist/tex/generic/xkeyval/keyval.tex))) 
    ! Extra \else. 
    l.227     \else 
     
    ? x
     
    

    There is a patch for this. Get the updated standalone.sty and replace the current installed one with it. The standalong.sty can be found at https: //bitbucket.org/martin_scharrer/standalone/raw/635aacfa0e8f2cba4f4086f4f15d57791b18bf64/standalone.sty

    Replace the file /usr/local/texlive/2013/texmf-dist/tex/latex/standalone/standalone With it. Now this problem will go away.

  2. Install make4ht
  3. fix tex4ht.env file to improve the fonts generated when making images for math. see elsewhere here for instructions. This step is not not needed any more, since I switched to make4ht for compiling, since make4ht does not use tex4ht.env, but if you are not using make4ht, then tex4ht.env is still used by standard htlatex command.

3.34 installation of TeX Live 2013

This is the log from

download http://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz

>ls -l 
total 0 
drwxrwxrwx 1 me me 0 Jan 16 18:34 install-tl-20140116 
>cd install-tl-20140116/ 
>ls -l 
total 89 
-rwxrwxrwx 1 me me  1157 May 31  2010 index.html 
-rwxrwxrwx 1 me me 79388 Sep 15 15:16 install-tl 
-rwxrwxrwx 1 me me  2098 Sep 28  2006 LICENSE.CTAN 
-rwxrwxrwx 1 me me  5086 Jun  5  2011 LICENSE.TL 
-rwxrwxrwx 1 me me   183 Aug  9  2008 README 
drwxrwxrwx 1 me me     0 Jan 16 18:34 readme-html.dir 
drwxrwxrwx 1 me me     0 Jan 16 18:34 readme-txt.dir 
-rwxrwxrwx 1 me me   250 Aug  9  2008 README.usergroups 
-rwxrwxrwx 1 me me   360 May 29  2013 release-texlive.txt 
drwxrwxrwx 1 me me     0 Jan 16 18:34 texmf-dist 
drwxrwxrwx 1 me me     0 Jan 16 18:34 tlpkg 
>
 

now run the installer as root sudo ./install-tl

[sudo] password for me: 
Loading http://mirrors.rit.edu/CTAN/systems/texlive/tlnet/tlpkg/texlive.tlpdb 
Installing TeX Live 2013 from: http://mirrors.rit.edu/CTAN/systems/texlive/tlnet 
Platform: i386-linux => 'Intel x86 with GNU/Linux' 
Distribution: net  (downloading) 
Using URL: http://mirrors.rit.edu/CTAN/systems/texlive/tlnet 
Directory for temporary files: /tmp 
 
======================> TeX Live installation procedure <===================== 
 
======>   Letters/digits in <angle brackets> indicate   <======= 
======>   menu items for commands or options            <======= 
 
 Detected platform: Intel x86 with GNU/Linux 
 
 <B> binary platforms: 1 out of 21 
 
 <S> set installation scheme (scheme-full) 
 
 <C> customizing installation collections 
     44 collections out of 45, disk space required: 3533 MB 
 
 <D> directories: 
   TEXDIR (the main TeX directory): 
     /usr/local/texlive/2013 
   TEXMFLOCAL (directory for site-wide local files): 
     /usr/local/texlive/texmf-local 
   TEXMFSYSVAR (directory for variable and automatically generated data): 
     /usr/local/texlive/2013/texmf-var 
   TEXMFSYSCONFIG (directory for local config): 
     /usr/local/texlive/2013/texmf-config 
   TEXMFVAR (personal directory for variable and automatically generated data): 
     ~/.texlive2013/texmf-var 
   TEXMFCONFIG (personal directory for local config): 
     ~/.texlive2013/texmf-config 
   TEXMFHOME (directory for user-specific files): 
     ~/texmf 
 
 <O> options: 
   [ ] use letter size instead of A4 by default 
   [X] allow execution of restricted list of programs via \write18 
   [X] create all format files 
   [X] install macro/font doc tree 
   [X] install macro/font source tree 
 
 <V> set up for portable installation 
 
Actions: 
 <I> start installation to hard disk 
 <H> help 
 <Q> quit 
 
Enter command: I 
 
Installing to: /usr/local/texlive/2013 
Installing [0001/2785, time/total: ??:??/??:??]: 12many [376k] 
Installing [0002/2785, time/total: 00:01/01:16:21]: 2up [66k] 
Installing [0003/2785, time/total: 00:02/02:10:06]: Asana-Math [458 
..... 
  go make coffee now and come back in 1 hr or so.. 
........... 
system          | lua | dumping '/usr/local/texlive/2013/texmf-var/luatex-cache/context/a86c089b384a3076dc514ba966a1fac9/trees/929f6dbc83f6d3b65dab91f1efa4aacb.lua' into '/usr/local/texlive/2013/texmf-var/luatex-cache/context/a86c089b384a3076dc514ba966a1fac9/trees/929f6dbc83f6d3b65dab91f1efa4aacb.luc' stripped 
resolvers       | caching | 'files' compiled to '/usr/local/texlive/2013/texmf-var/luatex-cache/context/a86c089b384a3076dc514ba966a1fac9/trees/929f6dbc83f6d3b65dab91f1efa4aacb.luc' 
mtxrun          | 
mtxrun          | runtime: 2.546 seconds 
done 
pre-generating all format files (fmtutil-sys --all), be patient...done 
running package-specific postactions 
finished with package-specific postactions 
 
 See 
   /usr/local/texlive/2013/index.html 
 for links to documentation.  The TeX Live web site 
 contains updates and corrections: http://tug.org/texlive. 
 
 TeX Live is a joint project of the TeX user groups around the world; 
 please consider supporting it by joining the group best for you. The 
 list of user groups is on the web at http://tug.org/usergroups.html. 
 
 
 Add /usr/local/texlive/2013/texmf-dist/doc/info to INFOPATH. 
 Add /usr/local/texlive/2013/texmf-dist/doc/man to MANPATH 
   (if not dynamically found). 
 
 Most importantly, add /usr/local/texlive/2013/bin/i386-linux 
 to your PATH for current and future sessions. 
 
 Welcome to TeX Live! 
Logfile: /usr/local/texlive/2013/install-tl.log 
>
 

Here is the logfile install-tl.log.txt

To update do

sudo `which tlmgr` update --self --all --reinstall-forcibly-removed 
 
[sudo] password for me: 
 
tlmgr: package repository http://ctan.mirrors.hoobly.com/systems/texlive/tlnet 
tlmgr: saving backups to /usr/local/texlive/2013/tlpkg/backups 
[1/1, ??:??/??:??] update: texlive.infra [299k] (31401 -> 31673) ... done 
Restarting tlmgr to complete update ... 
tlmgr: package repository http://ctan.mirrors.hoobly.com/systems/texlive/tlnet 
tlmgr: saving backups to /usr/local/texlive/2013/tlpkg/backups 
[  1/293] auto-remove: lgrx ... done 
[  2/293] auto-remove: gmeometric ... done 
[  3/293, ??:??/??:??] update: Asana-Math [458k] (27228 -> 31750) ... done 
[  4/293, 00:05/55:11] update: abntex2 [4526k] (31530 -> 32490) ... done 
[  5/293, 00:10/10:08] update: achemso [469k] (31608 -> 31893) ... done 
[  6/293, 00:12/11:07] update: acro [532k] (31571 -> 32450) ... done 
[  7/293, 00:20/16:53] update: amiri [1637k] (30816 -> 32506) ... done 
[  8/293, 00:25/16:34] update: animate [3085k] (31241 -> 31766) ... done 
[  9/293, 00:28/13:12] update: autonum [379k] (30979 -> 32126) ... done 
...... 
[289/293, 15:22/15:22] update: collection-plainextra [1k] (30395 -> 31683) ... done 
[290/293, 15:23/15:23] update: collection-pstricks [1k] (31016 -> 32514) ... done 
[291/293, 15:24/15:24] update: collection-publishers [1k] (31532 -> 32440) ... done 
[292/293, 15:24/15:24] update: collection-science [1k] (30307 -> 32182) ... done 
[293/293, 15:25/15:25] update: scheme-context [1k] (29997 -> 32062) ... done 
tlmgr: package log updated: /usr/local/texlive/2013/texmf-var/web2c/tlmgr.log 
running mktexlsr ... 
done running mktexlsr. 
running mtxrun --generate ... 
done running mtxrun --generate. 
running updmap-sys ... 
done running updmap-sys. 
regenerating fmtutil.cnf in /usr/local/texlive/2013/texmf-var 
running fmtutil-sys --no-error-if-no-format --byengine ptex ... 
done running fmtutil-sys --no-error-if-no-format --byengine ptex. 
running fmtutil-sys --no-error-if-no-format --byengine eptex ... 
done running fmtutil-sys --no-error-if-no-format --byengine eptex. 
running fmtutil-sys --no-error-if-no-format --byengine pdftex ... 
done running fmtutil-sys --no-error-if-no-format --byengine pdftex. 
running fmtutil-sys --byfmt cont-en ... 
done running fmtutil-sys --byfmt cont-en. 
running fmtutil-sys --byfmt pdfcsplain ... 
done running fmtutil-sys --byfmt pdfcsplain. 
>

The /usr/local/texlive/2013/texmf-var/web2c/tlmgr.log log file contains the full listing. It appends the log of each update to the last update. so the log will contain all the updates done and not just the one just done

[Fri Jun 21 01:03:25 2013] update: dvipdfmx.i386-linux (30205 -> 30845) 
[Fri Jun 21 01:03:28 2013] update: dvipng.i386-linux (30088 -> 30845) 
[Fri Jun 21 01:03:50 2013] update: luatex.i386-linux (30739 -> 30845) 
..... 
[Tue Jan  7 17:39:02 2014] update: collection-latexextra (31599 -> 32457) 
[Tue Jan  7 17:39:03 2014] update: collection-metapost (30387 -> 32455) 
[Tue Jan  7 17:39:04 2014] update: collection-music (31524 -> 32405) 
[Tue Jan  7 17:39:04 2014] update: collection-pictures (31517 -> 32320) 
[Tue Jan  7 17:39:05 2014] update: collection-plainextra (30395 -> 31683) 
[Tue Jan  7 17:39:06 2014] update: collection-pstricks (31016 -> 32514) 
[Tue Jan  7 17:39:06 2014] update: collection-publishers (31532 -> 32440) 
[Tue Jan  7 17:39:07 2014] update: collection-science (30307 -> 32182) 
[Tue Jan  7 17:39:08 2014] update: scheme-context (29997 -> 32062)

To start the tlmgr GUI, must be root, and the command is

sudo `which tlmgr` gui
 

got TeX Live DVD today. Here is the front and the back

3.35 on using multicols

  1. to force a figure in a column, let includegraphics resize it using \includegraphics[width=\columnwidth]{image}

3.36 How to place figures

Using \begin{figure} makes images float and so hard to control the location. Instead, can use just \includegraphics{name} but to get use caption, use this method by Gonzalo Medina

When this viewed in HTML, tex4ht puts one image below the other. It seems tex4ht does not support minipages.

To do the same for tex4ht try the following, using multicols new support added to tex4ht

\documentclass{article} 
\usepackage[demo]{graphicx} 
\usepackage{capt-of} 
\usepackage{lipsum}% 
 
\begin{document} 
\lipsum[1] 
\begin{center} 
  \includegraphics{foo} 
  \captionof{figure}{A non floating figure} 
  \label{fig:test} 
\end{center} 
 
\lipsum[2] 
\end{document}
 

PIC

Figure 3.1: result of the above

These are different examples of placing figures

\documentclass{article} 
\usepackage{subfigure} 
\usepackage{lipsum} 
\usepackage[demo]{graphicx} 
\usepackage[utf8]{inputenc} 
 
\begin{document} 
\lipsum[1] 
 
\begin{figure}[ht!] 
     \begin{center} 
% 
        \subfigure[Caption of First Figure]{% 
            \label{fig:first} 
            \includegraphics[width=0.4\textwidth]{FirstFigure} 
        }% 
        \subfigure[Caption of Second Figure]{% 
           \label{fig:second} 
           \includegraphics[width=0.4\textwidth]{SecondFigure} 
        }\\ %  ------- End of the first row ----------------------% 
        \subfigure[Caption of Third Figure]{% 
            \label{fig:third} 
            \includegraphics[width=0.4\textwidth]{ThirdFigure} 
        }% 
        \subfigure[Caption of Fourth Figure]{% 
            \label{fig:fourth} 
            \includegraphics[width=0.4\textwidth]{FourthFigure} 
        }% 
% 
    \end{center} 
    \caption{% 
        The l-o-n-g caption for all the subfigures 
        (FirstFigure through FourthFigure) goes here. 
     }% 
   \label{fig:subfigures} 
\end{figure} 
 
\lipsum[2-5] 
\end{document}
 

references:

  1. http://tex.stackexchange.com/questions/107363/putting-multiple-ima ges-in-a-page

3.37 Finding definitions of LaTeX control sequences?

use texdef -t latex <control word>

For example

>texdef -t latex input 
 
\input: 
macro:->\@ifnextchar \bgroup \@iinput \@@input 
 
> 
>texdef -t latex pi 
 
\pi: 
\mathchar"119 
 
 
\the\pi: 
281 
 
>texdef -t latex frac 
 
\frac: 
macro:#1#2->{\begingroup #1\endgroup \over #2}
 

3.38 wrapping text around figures

see http://tex.stackexchange.com/questions/56176/handling-of-wrapfig-pictures-in-latex and http://texblog.org/tag/wrapfigure/ also there is wraptable see http://tex.stackexchange.com/questions/49300/wrap-text-around-a-tabular

From the first link:

\documentclass{article} 
\usepackage{wrapfig} 
\usepackage{lipsum} 
 
\begin{document} 
 
\lipsum[1-4] 
\begin{wrapfigure}{R}{5cm} 
\centering 
\rule{3cm}{7cm} 
\end{wrapfigure} 
\lipsum[1-6] 
 
\end{document}
 

3.39 what tex editors to use?

list of some I tried

  1. Texmaker (shows structure of document on left panel. Ok, but it gets confused with \Verbatim that has also Latex code in it, it think it is part of the document and shows it in the structure of the actual document as well.
  2. texworks
  3. Kyle on Linux (nice)

3.40 How to define text block to use in more than one place?

Thanks for TorbjørnT. from Tex forum for these methods.

Sometimes I needed to define some text and put it in 2 different places.

If the text has no verbatim in it, this method can be used

\documentclass{article}% 
\begin{document} 
 
\newcommand\mytext{ 
text with some with no verbatim 
 
more text here 
} 
 
\mytext 
 
\renewcommand\mytext{ 
more text with here 
 
more text here also....... 
} 
 
\mytext 
 
\end{document}
 

But if the text has verbatim in it, the above does not work. Use this method

\documentclass{article}% 
\usepackage{filecontents} 
\begin{document} 
 
\begin{filecontents*}{somefile.txt} 
Text with \verb|Initialization|  verbatim it. 
 
This would now be put in text file, then read again 
\end{filecontents*} 
 
\input{somefile.txt} 
\end{document}
 

3.41 adjusting text, parskip, parindent

From http://www.andy-roberts.net/writing/latex/tables

 
 There are also things known as command lengths, which are not 
 fixed values as they depend on the configuration of the current 
 document class and/or preamble. Useful ones include: 
 
    * \parindent - the size of the paragraph indent 
    * \baselineskip - vertical distance between lines. 
    * \parskip - the extra space between paragraphs. 
    * \textwidth - the width of a line of text in the local 
                   environment (e.g., the 
                   lines are commonly narrower in the abstract 
                   than in the normal text). 
    * \textheight - the height of the text on the page.
 

try this sometime

% 
% this makes list spacing much better. 
% 
\newenvironment{my_enumerate}{ 
\begin{enumerate} 
  \setlength{\itemsep}{1pt} 
  \setlength{\parskip}{0pt} 
  \setlength{\parsep}{0pt}}{\end{enumerate} 
}
 

What I do is insert this code somewhere at the top of my LaTeX document, before I need to create any enumerations. Then, later in the document, when I do want to create an enumeration, instead of using the enumerate tag, I use the my_enumerate

3.42 How to reduce size of math in one place only?

\text{\scriptsize $\sin(x)$}
 

Use different size as needed, footnotesize or tiny and others.

3.43 How to hand written fonts and other fonts using xelatex?

This file can only be compiled by xelatex of lualatex

\documentclass{article} 
\usepackage[no-math]{fontspec} 
 
 
\setmainfont[ 
  Ligatures=TeX, 
]{Architect} 
 
 
\begin{document} 
  This is some TEXT. 
\end{document}
 

Then compile using xelatex foo.tex. The fonts used above, called Architect was downloaded from http://www.911fonts.com/font/download_StylusITCTTRegular_66.htm

See using-handwriting-font-in-proofs for more information.

Some fonts utilities on linux

    kcharselect 
    gfontsel 
    xfontsel 
    xlsfonts 
    chkfontpath 
    fslsfonts
 

It seems on Linux one needs to just create $HOME/.fonts/ folder and put the .tff files there.

For example, I downloaded zip file from the above, extracted it, and copied one .tff file to

>pwd 
/home/me/.fonts 
 
>ls -l 
-rwxr-xr-x 1 me me 36708 Sep 22 02:09 17273_architectbold.ttf
 

Now, make sure to rename the file above to match the actual font name as given inside the file. Double clicking on the file at least on windows, and look for the font name. do not use the file name itself. Must rename the file to match the font name. For the above, I did

>mv 17273_architectbold.ttf Architect-Bold.ttf

Since Architect-Bold was the actual font name.

And changed the latex file to the exact file name above as follows

\documentclass{article} 
\usepackage[no-math]{fontspec} 
 
\setmainfont[ 
  Ligatures=TeX, 
]{Architect-Bold} 
 
\begin{document} 
  This is some TEXT. 
\end{document}
 

The command fc-cache might be also useful to run after doing the above just in case. Use xelatex and not lulatex for the above. It seems there is difference on how fonts are found depending on which one to use. The above instructions are for xelatex which is what I used. It might work with lulatex, do not know now.

See fontspec-xelatex-finding-fonts-by-name-installed-or-in-texmfhome

To use times package, just add the line

3.44 How to use Times font for the whole document in Latex?

Just add this line

\usepackage{times}

See how-do-you-change-the-document-font-in-latex for more information.

3.45 how to pass variable to latex to change the compile content?

I use this method which works ok for me. I have a file called switch.tex where the switch is set to true or false. I have to edit this file to change the switch. Then in the main latex document, I input this file. This diagram shows the process.

\ifbool{switch} 
{.... latex code to compile when switch is true....} 
{.... latex code to compile when switch is false....}
 

pict

3.46 how to generate Latex from other programming languages?

This shows how to use other environments to generate Latex code. In Mathematica

s = ToString["\\documentclass[12pt,titlepage]{article} 
\\begin{document} 
It is known that $\\sin(0)=" <> ToString[Sin[0]] <> "$ 
\\end{document}"]; 
 
file = OpenWrite["C:\\tmp\\p.tex", PageWidth -> Infinity]; 
WriteString[file, s]; 
Close[file];
 

This generates the Latex file p.tex

\documentclass[12pt,titlepage]{article} 
\begin{document} 
It is known that $\sin(0)=0$ 
\end{document}
 

Using Python

import math 
s=r""" 
\documentclass[12pt,titlepage]{article} 
\begin{document} 
It is known that $\sin(0)="""+repr(math.sin(0))+r"""$ 
\end{document}""" 
 
text_file = open(r"C:\tmp\p.tex", "w") 
text_file.write(s) 
text_file.close()
 

The above generates the Latex file

\documentclass[12pt,titlepage]{article} 
\begin{document} 
It is known that $\sin(0)=0.0$ 
\end{document}
 

From C++ (needs C++11)

#include <iostream> 
#include <string> 
#include <math.h> 
using namespace std; 
 
 
int main() 
{ 
            //int r = 5; 
        string s =R"( 
 
\documentclass[12pt,titlepage]{article} 
\begin{document} 
 It is known that (a) $\sin(\pi)=)" + std::to_string(sin(M_PI)) + R"($ 
\end{document} 
 
)"; 
 
        cout << s << endl; 
        return 0; 
}
 

And now compile and run

>g++ -Wall -std=c++0x try_string_literal.cpp 
>./a.out 
 
 
\documentclass[12pt,titlepage]{article} 
\begin{document} 
 It is known that (a) $\sin(\pi)=0.000000$ 
\end{document}
 

3.47 how to debug Latex?

Add --debug --interactive

3.48 How to find history of Tex? Family tree?

type texdoc tex-overview.pdf

3.49 Where to put a style file that is downloaded and not part of TexLive?

cd `kpsewhich -var-value=TEXMFHOME`
 

and make directory tex/latex/mystuff/ and put the file there.

Verify using kpsewhich filename.sty.

Reference: answer at tex stackexchange

3.50 How to convert pdf to eps?

pdftops -f 1 -l 1 -eps pic.pdf

3.51 what are values of extensions for images

Using this:

\documentclass[11pt,notitlepage]{article}% 
\usepackage{graphicx} 
\begin{document} 
 
\makeatletter 
\Gin@extensions 
\makeatother 
 
\end{document}
 

Compiled with htlatex gives

.eps,.ps,.eps.gz,.ps.gz,.eps.Z,.mps

and compiled with pdflatex gives

.png,.pdf,.jpg,.mps,.jpeg,.jbig2,.jb2,.PNG,.PDF,.JPG,.JPEG,.JBIG2,.JB2,.eps

And compiled with lualatex gives

.png,.pdf,.jpg,.mps,.tif,.jpeg,.PNG,.PDF,.JPG,.JPEG,.eps

3.52 How to include pdf pages as is in Latex

The number of pages of the pdf is first found, then a loop is used to load each page. Make sure to use \clearpage before, so that the first pdf page is on a new page and make sure to clear the page also after each page in the loop.

Here is an example

 
\usepackage{tikz} 
\usepackage{pgffor} 
.... 
 
\pdfximage{foo.pdf} 
\foreach \n in {1,...,\the\pdflastximagepages} 
{ 
\begin{tikzpicture}[remember picture,overlay] 
  \node[inner sep=0pt] at (current page.center) 
{ 
   \includegraphics[page=\n]{foo.pdf}}; 
   \end{tikzpicture} 
   \clearpage 
}
 

If you know the pdf file has only one page, then the following is enough

\clearpage 
\begin{tikzpicture}[remember picture,overlay] 
  \node[inner sep=0pt] at (current page.center) 
{ 
     \includegraphics[page=1,scale=0.9]{foo.pdf} 
}; 
\end{tikzpicture} 
\clearpage
 

3.53 How to automatically build images needed for the latex file?

I put all my images needed for the document in an images/ folder below the main document folder. Using recusrive make, the document Makefile has this line at its top

DIRS = images 
 
include common.mk 
...
 

Then the Makefile in the images/ file looks like this

DIRS = 
 
include common.mk 
 
FILES := $(shell ls -1 *.pdf) 
#$(info $$FILES is [${FILES}]) 
TARGET = $(basename $(FILES)) 
#$(info $$TARGET is [${TARGET}]) 
 
all:: ${TARGET:=.svg} 
        @echo "Finished building [$?]" 
 
%.svg : %.pdf 
        prep $< 
 
.PHONY: clean 
clean :: 
        -rm -f ${TARGET:=.svg}
 

Where prep is my script I use to crop the images and generate SVG image from each. Here it is

>cat `which prep` 
#!/bin/bash 
set -u 
set -e 
set -o pipefail 
 
for file in $1; do 
    filename=${file%.*} 
    pdfcrop --margins 10 --clip "$filename.pdf" "$filename.pdf" 
    pdf2svg "$filename.pdf" "$filename.svg" 
#    pdftops -f 1 -l 1  -level3 -eps "$filename.pdf" 
done 
my_courses>
                                                                                    
                                                                                    
 

I use pdf file for the source of all the images. The above setup takes care of updating the images if one of them changes when compiling the latex file.

3.54 Some lualatex examples using Lua inside Latex

3.54.1 Making counter

% !TEX TS-program = lualatex 
\documentclass{article} 
\usepackage{luacode} 
\usepackage{amsmath} 
%------------------------ 
\begin{luacode} 
local x = 0 
function add() 
    x = x +1 
    tex.print(x) 
end 
 
function sub() 
    x = x - 1 
    tex.print(x) 
end 
 
function reset() 
    x = 0 
end 
 
\end{luacode} 
\newcommand\add[0]{ \directlua{add()}}% 
\newcommand\sub[0]{ \directlua{sub()}}% 
\newcommand\reset[0]{ \directlua{reset()}}% 
%------------------- 
\begin{document} 
\reset 
\add 
\add 
\sub 
\add 
\end{document}
 

3.54.2 simplify fraction

see http://tex.stackexchange.com/questions/253693/reducing-fraction-using-latex-3/253716\#253716

\documentclass{article} 
\usepackage{luacode} 
\usepackage{amsmath} 
%------------------------ 
\begin{luacode} 
function simplify(a,b) 
  local function gcd(a,b) 
    if b ~= 0 then 
        return gcd(b, a % b) 
    else 
        return math.abs(a) 
    end 
  end 
 
t = gcd(a, b) 
tex.print("\\frac{"..a/t.."}{"..b/t.."}") 
end 
\end{luacode} 
\newcommand\simplify[2]{\directlua{simplify(#1,#2) }}% 
%------------------- 
\begin{document} 
\noindent Can I make \LaTeX{} reduce a fraction automatically?\\[\baselineskip] 
For example, I would like the fraction 
\begin{equation*} 
  \frac{278\,922}{74\,088} 
\end{equation*} 
 
to be reduced to 
 
\begin{equation*} 
  \simplify{278922}{74088} 
\end{equation*} 
\end{document}
 

The output of the above is

\begin {equation*} \frac {278\,922}{74\,088} \end {equation*}

to be reduced to

\begin {equation*} {278922}{74088} \end {equation*}

3.54.3 read CVS field to Latex table

This uses lua function to read the specific field in the CVS file. For example, given this CVS file in the directory

123,Poty city,Poti,red,-295731.42857144,617222.85714285 
124,Lanchhuti city,Poti,red,-299217.14285715,647851.42857142 
125,Ozurgeti city,Poti,red,-317217.14285715,648422.85714285 
126,Samtredia city,Poti,red,-287502.85714287,672022.85714285
 

and you want to insert, say field located at row 2 and column 5, which is -299217.14285715 in the above, and field at row 1 and column 3, which is Poti then do

\begin{tabular}{|l|l|l|l|l|}\hline 
    1  & \getField{1}{2}   & 3  & 4                & 5 \\\hline 
    6  & 7                 & 8  & \getField{2}{5}  & 9  \\\hline 
    10 & 11                & 12 & 13               & 14 \\\hline 
\end{tabular}
 

The full code is below. I googled lua code to parse CVS files, there are few on the net, I found one that worked and used it. The CVS file is read automatically. Change the cvs file name in the code below and its path as needed. The latex file needs to be compiled with lualatex not pdflatex

\documentclass[]{article} 
\usepackage{luacode} 
 
\begin{luacode*} -- CVS API: http://nocurve.com/simple-csv-read-and-write-using-lua/ 
 local function split(str, sep) 
     fields={} 
     local matchfunc = string.gmatch(str, "([^"..sep.."]+)") 
     if not matchfunc then return {str} end 
     for str in matchfunc do 
         table.insert(fields, str) 
     end 
     return fields 
end 
 
function read(path, sep, tonum) 
    tonum = tonum or true 
    sep = sep or ',' 
    local csvFile = {} 
    local file = assert(io.open(path, "r")) 
    for line in file:lines() do 
        fields = split(line, sep) 
        if tonum then -- convert numeric fields to numbers 
            for i=1,#fields do 
                fields[i] = tonumber(fields[i]) or fields[i] 
            end 
        end 
        table.insert(csvFile, fields) 
    end 
    file:close() 
    return csvFile 
end 
 
local m = read('./c.cvs') -- read file csv file to local matrix m 
 
function getField(row,col) -- API to latex command below 
tex.print(m[row][col]) 
end 
 
\end{luacode*} 
\newcommand\getField[2]{\directlua{getField(#1,#2) }}% 
 
\begin{document} 
 
\begin{table}[] 
    \centering 
    \caption{My example} 
    \begin{tabular}{|l|l|l|l|l|}\hline 
        1  & \getField{1}{2}   & 3  & 4                & 5 \\\hline 
        6  & 7                 & 8  & \getField{2}{5}  & 9  \\\hline 
        10 & 11                & 12 & 13               & 14 \\\hline 
    \end{tabular} 
\end{table} 
 
\end{document}
 

reference tex stackexchange

This below reads a while CVS file to a latex table

\documentclass[]{article} 
\usepackage{luacode} 
 
\begin{luacode*} -- CVS API thanks to http://nocurve.com/simple-csv-read-and-write-using-lua/ 
 local function split(str, sep) 
     fields={} 
     local matchfunc = string.gmatch(str, "([^"..sep.."]+)") 
     if not matchfunc then return {str} end 
     for str in matchfunc do 
         table.insert(fields, str) 
     end 
     return fields 
end 
 
function read(path, sep, tonum) 
    tonum = tonum or true 
    sep = sep or ',' 
    local csvFile = {} 
    local file = assert(io.open(path, "r")) 
    for line in file:lines() do 
        fields = split(line, sep) 
        if tonum then -- convert numeric fields to numbers 
            for i=1,#fields do 
                fields[i] = tonumber(fields[i]) or fields[i] 
            end 
        end 
        table.insert(csvFile, fields) 
    end 
    file:close() 
    return csvFile 
end 
 
function getCVS(fileName) 
 local m = read(fileName) -- read file csv1.txt to matrix m 
 local nRow = #m 
 local nCol = #m[1] 
 
 tex.sprint("\\begin{tabular}{") 
 for j=1,#m[1] do 
     tex.sprint("|l") 
 end 
 tex.print("|}\\hline") 
 
 for i = 1,nRow do 
   for j = 1,nCol do 
       tex.sprint(m[i][j]) 
       if j<nCol then tex.sprint("&") end 
   end 
   tex.print("\\\\ \\hline") 
 end 
 tex.print("\\end{tabular}") 
end 
 
\end{luacode*} 
\newcommand\getCVS[1]{\directlua{getCVS(#1) }}% 
 
\begin{document} 
 
\begin{table}[] 
    \centering 
    \caption{My CVS file in a Latex table} 
    \getCVS{"c.cvs"} 
\end{table} 
 
\end{document}
 

3.54.4 reversing enumeration list

Given enumeration list, where each item just uses one line, to reverse it:

% !TEX TS-program = lualatex 
\documentclass{article} 
\usepackage{luacode} 
\usepackage{amsmath} 
%------------------------ 
\begin{luacode*}  -- copy the list here as is. 
data=[[\item 2001 
      \item 2002 
      \item 2003 
      \item 2005 was a very good year 
      \item 2006 was also a very good year 
      \item 2007 
      ]] 
 
function string:split(sep) --http://lua-users.org/wiki/SplitJoin 
        local sep, fields = sep or ":", {} 
        local pattern = string.format("([^%s]+)", sep) 
        self:gsub(pattern, function(c) fields[#fields+1] = c end) 
        return fields 
end 
 
function flip() 
    lines = data:split("\n") 
    tex.print("\\begin{enumerate}") 
    for i=#lines,1,-1 do 
       tex.print(lines[i]) 
    end 
    tex.print("\\end{enumerate}") 
end 
\end{luacode*} 
\newcommand\flip[0]{ \directlua{flip()}}% 
 
\begin{document} 
\flip{} 
\end{document}
 

Another way is

% !TEX TS-program = lualatex 
\documentclass{article} 
\usepackage{luacode} 
\usepackage{amsmath} 
 
%------------------------ 
\begin{luacode*} 
function split(str, pat)  --http://lua-users.org/wiki/SplitJoin 
   local t = {}  -- NOTE: use {n = 0} in Lua-5.0 
   local fpat = "(.-)" .. pat 
   local last_end = 1 
   local s, e, cap = str:find(fpat, 1) 
   while s do 
      if s ~= 1 or cap ~= "" then 
     table.insert(t,cap) 
      end 
      last_end = e+1 
      s, e, cap = str:find(fpat, last_end) 
   end 
   if last_end <= #str then 
      cap = str:sub(last_end) 
      table.insert(t, cap) 
   end 
   return t 
end 
 
function flip(data) 
    items = split(data,"\\item") 
    tex.print("\\begin{enumerate}") 
    for i=#items,1,-1 do 
       tex.print("\\item "..items[i]) 
    end 
    tex.print("\\end{enumerate}") 
end 
\end{luacode*} 
%------------------- 
 
\begin{document} 
This is my enumeration list 
\begin{enumerate} 
      \item 2001 
      \item 2002 
      \item 2003 
\end{enumerate} 
 
Here it is flipped: 
\directlua{flip(\luastring{\unexpanded{% 
      \item 2001 
      \item 2002 
      \item 2003 
      }})} 
\end{document}
 

The result of the above is

This is my enumeration list

  1. 2001
  2. 2002
  3. 2003

Here it is flipped:

  1. 2003
  2. 2002
  3. 2001