Get Started with Latex on Linux

Get started with Latex on Linux

First you'll need to Install it:

  • If you're using a distro which packages LaTeX (almost all will do) then look for texlive or tetex. TeX Live is the newer of the two, and is replacing tetex on most distributions now.

If you're using Debian or Ubuntu, something like:

<code>apt-get install texlive</code>

..will get it installed.

RedHat or CentOS need:

<code>yum install tetex</code>

Note : This needs root permissions, so either use su to switch user to root, or prefix the commands with sudo, if you aren't already logged in as the root user.

Next you'll need to get a text editor. Any editor will do, so whatever you are comfortable with. You'll find that advanced editors like Emacs (and vim) add a lot of functionality and so will help with ensuring that your syntax is correct before you try and build your document output.

Create a file called test.tex and put some content in it, say the example from the LaTeX primer:

\documentclass[a4paper,12pt]{article}
\begin{document}

The foundations of the rigorous study of \emph{analysis}
were laid in the nineteenth century, notably by the
mathematicians Cauchy and Weierstrass. Central to the
study of this subject are the formal definitions of
\emph{limits} and \emph{continuity}.

Let $D$ be a subset of $\bf R$ and let
$f \colon D \to \mathbf{R}$ be a real-valued function on
$D$. The function $f$ is said to be \emph{continuous} on
$D$ if, for all $\epsilon > 0$ and for all $x \in D$,
there exists some $\delta > 0$ (which may depend on $x$)
such that if $y \in D$ satisfies
\[ |y - x| < \delta \]
then
\[ |f(y) - f(x)| < \epsilon. \]

One may readily verify that if $f$ and $g$ are continuous
functions on $D$ then the functions $f+g$, $f-g$ and
$f.g$ are continuous. If in addition $g$ is everywhere
non-zero then $f/g$ is continuous.

\end{document}

Once you've got this file you'll need to run latex on it to produce some output (as a .dvi file to start with, which is possible to convert to many other formats):

latex test.tex

This will print a bunch of output, something like this:

=> latex test.tex

This is pdfeTeX, Version 3.141592-1.21a-2.2 (Web2C 7.5.4)
entering extended mode
(./test.tex
LaTeX2e <2003/12/01>
Babel <v3.8d> and hyphenation patterns for american, french, german, ngerman, b
ahasa, basque, bulgarian, catalan, croatian, czech, danish, dutch, esperanto, e
stonian, finnish, greek, icelandic, irish, italian, latin, magyar, norsk, polis
h, portuges, romanian, russian, serbian, slovak, slovene, spanish, swedish, tur
kish, ukrainian, nohyphenation, loaded.
(/usr/share/texmf/tex/latex/base/article.cls
Document Class: article 2004/02/16 v1.4f Standard LaTeX document class
(/usr/share/texmf/tex/latex/base/size12.clo))
No file test.aux.
[1] (./test.aux) )
Output written on test.dvi (1 page, 1508 bytes).
Transcript written on test.log.

..don't worry about most of this output -- the important part is the Output written on test.dvi line, which says that it was successful.

Now you need to view the output file with xdvi:

xdvi test.dvi &

This will pop up a window with the beautifully formatted output in it. Hit `q' to quit this, or you can leave it open and it will automatically update when the test.dvi file is modified (so whenever you run latex to update the output).

To produce a PDF of this you simply run pdflatex instead of latex:

pdflatex test.tex

..and you'll have a test.pdf file created instead of the test.dvi file.

After this is all working fine, I would suggest going to the LaTeX primer page and running through the items on there as you need features for documents you want to write.

Future things to consider include:

  • Use tools such as xfig or dia to create diagrams. These can be easily inserted into your documents in a variety of formats. Note that if you are creating PDFs then you shouldn't use EPS (encapsulated postscript) for images -- use pdf exported from your diagram editor if possible, or you can use the epstopdf package to automatically convert from (e)ps to pdf for figures included with \includegraphics.

  • Start using version control on your documents. This seems excessive at first, but being able to go back and look at earlier versions when you are writing something large can be extremely useful.

  • Use make to run latex for you. When you start on having bibliographies, images and other more complex uses of latex you'll find that you need to run it over multiple files or multiple times (the first time updates the references, and the second puts references into the document, so they can be out-of-date unless you run latex twice...). Abstracting this into a makefile can save a lot of time and effort.

  • Use a better editor. Something like Emacs + AUCTeX is highly competent. This is of course a highly subjective subject, so I'll leave it at that (that and that Emacs is clearly the best option :)

Latex install packages in home

Yes, it's possible. You should set TEXINPUTS variable: it stores the directories where your files place:

TEXINPUTS=.:/your/desired/path

(Note the first . - this will the current working directory)

Copy your files to /your/desired/path and run mktexlsr /your/desired/path.

See man tex for more.

What is a good setup for LaTeX and R?

  1. Yes, though some people I know found switching from WinEdt a bit hard.
  2. I like gedit, the default text editor in Ubuntu, though there are a lot of other text editors that are also good. A matter of personal preference.
  3. Try RKWard in the Ubuntu Software centre.
  4. By searching in the Ubuntu software centre for "LaTeX" you will get some good results. I would try Texmaker.

Texmaker don't compile latex document on Ubuntu

This is what I did:

1- Install Latex compiler:

sudo apt-get install abntex

2- Install TexMaker:

sudo apt-get install texmaker

3- Run texmaker and load your Tex document

And you install next, too

sudo apt-get  install texlive-latex-base texlive-latex-extra texlive-latex-recommended texlive-fonts-recommended texmaker

How can I download all the Latex Packages to my ubuntu system?

Installed the followig commands on ubuntu local machine

sudo apt-get install texlive texstudio # for latex 
sudo apt-get install texlive-full # for full texlive packages
sudo apt-get install xzdec # for tlmgr

Also for online installation you can do this

wget -O http://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz
chmod u+x /tmp/install-tl-unx.tar.gz
cd /tmp && tar zxvf install-tl-unx.tar.gz
./install-tl

This will install latex packages on your server

How to install TeX live at newest version?

I followed samcarter_is_at_topanswers.xyz advice, but had to find the correct directory for my tlmgr executable. I found that through

  $ sudo find -iname 'tlmgr'

.. invoked at the root directory. Running

  $ /usr/local/texlive/2021/bin/x86_64-darwinlegacy/tlmgr --version

returned the newest version. However, that path was already set as described on the TeX Live page. For it to work, I deleted more directories that had been included in the 2018 installation version of TeX Live. I found those through

  $ sudo find -iname '*texlive*'

invoked at the root directory. Then

  $ tlmgr --version

returned the correct version.

Also, don't install TeX Live in /usr/local. Install it in your home directory.

Compiling Latex from Linux bash script

#! /bin/bash
NAME=`echo "$1" | cut -d'.' -f1`
pdflatex -file-line-error -halt-on-error $NAME.tex && xdg-open $NAME.pdf

Should do the trick.

Edit to address the question in the comment:

Sure, that works either with wrapping the other commands in a subshell:

pdflatex -file-line-error -halt-on-error $NAME.tex && ( xdg-open $NAME.pdf; command2; command 3 )

or by evaluating the return code in an if statement:

if [[ $? -eq 0 ]]; then
xdg-open $NAME.pdf
command2
command3
fi


Related Topics



Leave a reply



Submit