Showing posts with label LaTeX. Show all posts
Showing posts with label LaTeX. Show all posts

Wednesday, September 24, 2025

Updating TexLive's CTAN Repository

I encountered an error when attempting to install a LaTeX package using tlgmr

tlmgr intall Package_Name

A solution to address is to change the default repository or declare one on the command line

Declaring the repository on the command line can be cubsome. We can reset the default CTAN repository using command

tlmgr option repository https://mirror.ctan.org/systems/texlive/tlnet

The above command will select one and set it as the default one. However, if you wish to specify which one to use, we can use command

tlmgr option repository https://mirrors.ibiblio.org/pub/mirrors/CTAN/systems/texlive/tlnet

The mirrors can be looked up from the CTAN mirror page.

Tuesday, March 11, 2025

Installing TexLive Packages Using tlmgr from a Non-default Repository

From time to time, the default TexLive repository does not work for me when I try to install a package using tlmgr. One method to get around this is to use a non-default repository, e.g., to install the listings package, we can


tlmgr -repository https://mirrors.ibiblio.org/pub/mirrors/CTAN/systems/texlive/tlnet install listings

Perhaps, the trick part is not to find a mirror, rather it is to write the correct URL. This example serves as a template for that

Tuesday, January 17, 2023

Installing Missing LaTeX Packages?

I recently discovered that I can easily install missing LaTeX packages on Fedora Linux, that is, via


sudo dnf install 'tex(beamer.cls)' 
sudo dnf install 'tex(hyperref.sty)' 

Can we do the similar on Debian/Ubuntu distributions?

Reference

  1. https://docs.fedoraproject.org/en-US/neurofedora/latex/

Friday, July 12, 2019

Looking up TexLive Package Name using .sty Filename

I am using TexLive, and sometimes it reports that it cannot locate a .sty file. It is not always the case that the package name is identical to the .sty filename (less the extension). For instance, when LaTeX reports that it cannot locate manyfoot.sty. The following will fail because the package that has manyfoot.sty isn't manyfoot.

$ tlmgr install manyfoot
tlmgr.pl: package repository http://ctan.math.utah.edu/ctan/tex-archive/systems/texlive/tlnet (not verified: gpg unavailable)
tlmgr.pl install: package manyfoot not present in repository.
tlmgr.pl: action install returned an error; continuing.
tlmgr.pl: An error has occurred. See above messages. Exiting.

A method to figure out the package name is to use tlmgr to search TexLive repositories, i.e.,

tlmgr search --global --file STY_FILE_NAME

For the example of manyfoot.sty, we do,

$ tlmgr search --global --file  manyfoot.sty
tlmgr.pl: package repository http://ctan.math.utah.edu/ctan/tex-archive/systems/texlive/tlnet (not verified: gpg unavailable)
lwarp:
        texmf-dist/tex/latex/lwarp/lwarp-manyfoot.sty
ncctools:
        texmf-dist/tex/latex/ncctools/manyfoot.sty

after which we do,

$ tlmgr install ncctools
tlmgr.pl: package repository http://ctan.math.utah.edu/ctan/tex-archive/systems/texlive/tlnet (not verified: gpg unavailable)
[1/1, ??:??/??:??] install: ncctools [2430k]
running mktexlsr ...
done running mktexlsr.
tlmgr.pl: package log updated: C:/Applications/texlive/2019/texmf-var/web2c/tlmgr.log

Thursday, May 3, 2018

Breaking Long URL in LaTeX Documents

Sometimes we wish to break a long URL in a LaTeX document.  I am among many people who have struggled with this. The following summarizes the answers I found online,

  1. Pass hypens to the url package that is referenced in the hyperref package, e.g.,

    PassOptionsToPackage{hyphens}{url}\usepackage{hyperref}
      
  2. However, the above would not work when the long URL has hyphens to avoid confusion by design. To break a long URL that has hyphens, we can use

    \usepackage[hyphenbreaks]{breakurl}
    

  3. In the above, LaTeX works hard and attempts to break the long URL at some location. If the location is not to our liking, we add the \sloppy command right before the reference to an URL, e.g.,

    \sloppy
    \url{a-very-long-and-awkward-URL-with-many-hyphens}
    
The above is the summaries of the following two discussions,
  1. How to break long url in an item
  2. Forcing linebreaks in \url
Great discussions, folks. Thanks.

Thursday, March 3, 2016

Extra Fonts for LaTex using Texlive on Ubuntu

One day, when I compiled a LaTex file, I encountered the following error,


-- Verifying Times compatible math font.
** Times compatible math font not found, forcing.
** No Times compatible math font package found. newtxmath is required.

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

It appears that others also encountered similar. The solution is simple. It is just to install additional fonts that are Times compatible. I am using Texlive on a Ubuntu system. On Ubuntu, perhaps, other Debian-based Linux system, you can install additional fonts for LaTeX as follows,

sudo apt-get install texlive-fonts-extra

The error went away after I installed the package.

Wednesday, February 17, 2016

Tools for Writing

This is just a bookmark on a number of writing tools,
  • Jupyter Notebook. "The Jupyter Notebook is a web application for interactive data science and scientific computing."
  • Authorea. Authorea is the collaborative editor for research. Write and manage your documents in one place, for free. 
  •  Overleaf. Overleaf is a collaborative writing and publishing system for writing and previewing in LaTex.

Thursday, March 12, 2015

Converting PDF to EPS Figure for LaTeX

Sometimes we want to convert a figure in PDF format to EPS format and use the figure in a LaTex file. One important item we must take care is the bounding box of the figure. If the bounding box is not generated correctly, we would have a large area of wide space around the figure in final document.

In a Linux system, we have a set of free tools that can help us produce an appropriate bounding box and convert PDF format to EPS format.
On Ubuntu, you may install them using apt-get as follows,

sudo apt-get install \
     pdftk gv texlive-extra-utils \
     poppler-utils ghostscript ps2eps


Assume that PDF file foo.pdf contains an interesting figure in page 2 and we want to extract the figure for inserting it in a LaTex document. We would follow the steps below,
  1. Extract the page from the PDF file that contains the figure we would like to extract

    pdftk foo.pdf cat 2 output page2.pdf
    

    where foo.pdf is the input PDF file, page2.pdf  is the output PDF file, and 2 is the page number in the input PDF file.

  2. Measure roughtly the position and the dimension of a box that contains the figure using gv.
    
    gv page2.pdf
    

    We read the coordinates of the bottom left corner and the top right corner of the box from gv. Assume the readings are (61, 82) and (321, 161), respectivley.

  3. Crop the PDF file based on the box obtained in the above.
    
    pdfcrop --bbox "61 82 321 161" page2.pdf
    

    The output of this step is page2-crop.pdf.

  4. Crop the resulting PDF file from previous step to reduce white space around the figure.
    
    pdfcrop page2-crop.pdf
    

    The result is page2-crop-crop.pdf.

  5. Convert the PDF file to an EPS file.
    
    pdftops -eps page2-crop-crop.pdf page2.eps
    

    We could complete the last step using pdf2ps in Ghostscript instead of pdftops by the Poppler developers as the following two steps approach.
    
    pdf2ps page2-crop-crop.pdf 
    ps2eps page2-crop-crop.ps page2.eps
    

    However, we do not recommend pdf2ps, convinced by the argument made by Stefaan Lippens.

    As indicated by Stefaan Lippens, pdf2ps converts fonts in PDF files to bitmap fonts in resulting PS files. Some may consider this an advantage because the fonts used in the figure will always be "present" in the PDF files generated form the corresponding LaTeX files. However, as we discussed previously, it is not difficult to embedd all fonts in a PDF file.

Wednesday, February 25, 2015

Getting File Basebase without Extension in GNU Makefile

Sometimes we would like to write a generic rule in GNU makefiles.

For instance, we would like to write a rule to process a LaTex file and then process BibTex entries for any LaTeX files. We can write the rule as follows,


%.dvi: %.tex
    latex $<
    bibtex $(basename $<)
    latex $<
    latex $<

In the example, if we issue a command make example.tex, the value of $< is example.tex while $(basename $<) yields the basename without the extension. The basename without the extension is required for bibtex to work in this example.

This solution is provided by the discussion here.

Tuesday, February 24, 2015

Installing lineno.sty in Ubuntu and Fedora Linux

When we prepare a document using LaTeX, sometimes we want to include line numbers in an article. In many peer reviewed journals, it is a requirement to include line numbers in the output.

For instance, Elsevier LaTeX instructions has a LaTeX template whose LaTeX template file starts with

\documentclass[review]{elsarticle}

\usepackage{lineno,hyperref}

You system has not had the lineno package installed, if you encounter the following error when you compile your LaTex file that uses package lineno,

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

Type X to quit or  to proceed,
or enter new name. (Default extension: sty)

Enter file name:

Although you can download and install it from CTAN, you may be better off by installing the appropriate package provided by your system and let your system manage it. For instance, on Ubuntu Linux, we can install the textlive-humanities package,

sudo apt-get install texlive-humanities

For instance, on Fedora Linux, we can install the texlive-collection-humanities package,

sudo yum install texlive-collection-humanities 

The solution comes from the posts at here and here.

Thursday, November 13, 2014

Bibtex Entries for IETF RFCs and Internet-Drafts

Sometimes we want to cite the Internet Engineering Task Force's Request for Comment (RFC) or Internet-Draft documents. The Internet-Draft draft-carpenter-rfc-citation-recs-01 entitled "Recommendations of a committee on RFC citation issues" suggests a format to cite RFCs and Internet-Drafts.  Although the draft recommends that the RFC Editor create and maintain a canonical BibTeX file at a stable public location on the web server "www.rfc-editor.org", the BibTex files do not seem to have appeared on the website.

This post provides a means to produce a BibTex entry for a RFC or Internet-Draft document, generally comforming to the recommendation stated in the draft cited above, when the type of documents, RFC or Internet-Draft and the document number are provided. You may then copy and paste the BibTex entry to your .bib file. Note that the Internet-Draft number is not really a number, for instance, for the draft that mentioned above, the number is "draft-carpenter-rfc-citation-recs-01" (without quotation marks).


RFC Document Type and Number



To fill with a bibtex entry.

Friday, October 3, 2014

Conditionally Processing LaTeX Documents

Sometimes one may wish to process a LaTeX document based on a condition. For instance, one may wish to conditional process a resume written in LaTeX depending where she is sending the document, i.e., she may wish to expand certain sections, shrink certain sections, or exclude certain sections, in which way, she does not need to maintain multiple different documents that share significant amount of content.

We can use LaTex ifthen package to achieve the purpose. An example is given in this post.

However, some (this and this) suggests that the package is obsolete and we should use the etoolbox package.

I have two examples that use the ifthen package and the etoolbox package, respectively. The complete examples are in Github. I tested the examples on a Linux machine.

In the first example, we use  the etoolbox package and create a "toggle" file (toggle.tex) in the Makefile

ex_cond_1_long.pdf: ex_cond_1.tex
 [ ! -f toggle.tex ] || rm -f toggle.tex
 echo "\\\\toggletrue{long}" > toggle.tex
 pdflatex -jobname ex_cond_1_long ex_cond_1.tex
 
ex_cond_1_short.pdf: ex_cond_1.tex
 [ ! -f toggle.tex ] || rm -f toggle.tex
 echo "\\\\togglefalse{long}" > toggle.tex
 pdflatex -jobname ex_cond_1_short ex_cond_1.tex

The content of toggle.tex is now either,

\toggletrue{long}
or

\togglefalse{long}
Then, in the LaTex file (ex_cond_1.tex), one of two files (long.tex or short.tex) will be conditionally included,

\documentclass[11pt, letterpaper]{article}
\usepackage{etoolbox}
\newtoggle{long}

\input{toggle.tex}

\iftoggle{long}{
    \input{long.tex}
}{
    \input{short.tex}
}

The second example uses the ifthen packag. We demonstrate that we can pass a value from the command line using jobname as shown in the Makefile,

ex_cond_2_long.pdf: ex_cond_2.tex
 pdflatex -jobname ex_cond_2_long ex_cond_2.tex

ex_cond_2_short.pdf: ex_cond_2.tex
 pdflatex -jobname ex_cond_2_short ex_cond_2.tex

Based on whether the jobname is ex_cond_2_long or ex_cond_2_short, one of two files (long.tex or short.tex) will be conditionally included,

\ifthenelse{\equal{\detokenize{ex_cond_2_long}}{\jobname}}{
    \input{long.tex}
}{
    \input{short.tex}
}




Thursday, October 2, 2014

Wildcard Targets in a Makefile (Pattern Rules)

You may use "Wildcard" targets in GNU makefile. In GNU make, this is called Pattern Rules. I find this post is very helpful.  For those who do not  have the patience to read the documentation of GNU Make or to jump to the post, here is a few examples that serves as a summary.

To apply a rule to compile any C++ files, we can write a rule as follows,

CPP=g++
CLFAGS=-Wall

%.o:%.cpp
       $(CPP) $(CFLAGS) $< -o $@

To apply to rule to convert any LaTeX files to dvi files, any dvi files to PostScript files, and then any PostScript files to PDF files, we may write a set of rules as follows,

%.pdf: %.ps
 ps2pdf \
              -dPDFSETTINGS=/prepress \
              -dSubsetFonts=true \
              -dEmbedAllFonts=true \
              -dMaxSubsetPct=100 \
              -dCompatibilityLevel=1.4 $<

%.ps: %.dvi
       dvips -t letter $<

 
%.dvi: %.tex
       latex $<



Saturday, September 6, 2014

LaTeX: Embedding All Fonts in PDF

Many publishers are cautions about readers' experience and want to ensure all fonts are embedded in PDF files when you send your final camera-ready PDF files in.

We commonly use LaTeX to produce publication grade PDF files. However, some publishers warn about the use of pdflatex to compile LaTeX files to produce PDF files, suggesting pdflatex is the culprit. Perhaps, the problem is rather not with pdflatex, but with the configuration of pdflatex. My experience indicates that default configuration of most LaTeX distributions has already got the configuration right. However, my experience indicates that regardless I use pdflatex or the combination of latex, dvips, and ps2pdf, I have many occasions that not all fonts are embedded.

The issue is actually not with latex, but with figures generated by some third party tools. For instance, if you use Matlab to save figure as an eps file, for instance, the following Matlab script produces an eps file example_signal.eps showing a cosine signal.

num_periods = 10;

freq = 5;
sampling_interval = 1/100;
signal_length = num_periods * 1 / freq;
t = 1:sampling_interval:signal_length;
y = 10 * cos(2 * pi * freq * t + pi / 4);

plot(t, y);

xlabel('t');
ylabel('y');
set(gcf, 'PaperSize', [5 5*0.618]);
set(gcf, 'PaperPosition', [0 0 5 5*0.618]);
print('-depsc', 'example_signal');

Let us convert the eps file to a PDF file.


ps2pdf example_signal.eps
pdfcrop example_signal.pdf


Now let us verify if the resulting PDF file has had all fonts embedded,


pdffonts ./example_signal.pdf
name       type    encoding  emb sub uni object ID
---------- ------- --------- --- --- --- ---------
Helvetica  Type 1  Custom    no  no  no       8  0

The above shows that font Helvetica is not embedded. How do we make sure all fonts are embedded. You must include as the example shows, 5 switches in the ps2pdf command,


ps2pdf \
       -dPDFSETTINGS=/prepress \
       -dSubsetFonts=true \
       -dEmbedAllFonts=true \
       -dMaxSubsetPct=100 \
       -dCompatibilityLevel=1.4 ./example_signal.eps

pdffonts ./example_signal.pdf
name              type    encoding emb sub uni object ID
----------------- ------- -------- --- --- --- ---------
FHQQIQ+Helvetica  Type 1C Custom   yes yes no       8  0


We now see the font is embedded.

Note the following,
  • You must include the 5 switches in the ps2pdf command. If you miss one, fonts may not be all embedded. 
  • The command has no effect on PDF files, even though you can run ps2pdf against PDF files and no error or warning will be reported.

If you have a PDF file, but not its ps or eps file, you can use the steps below to convert the PDF file to a ps file and then convert the ps file back to a PDF file. The new PDF file will have all the fonts embedded, for instance,


pdf2ps example.pdf
ps2pdf \
       -dPDFSETTINGS=/prepress \
       -dSubsetFonts=true \
       -dEmbedAllFonts=true \
       -dMaxSubsetPct=100 \
       -dCompatibilityLevel=1.4 ./example.ps
That is all.

Thursday, October 24, 2013

Free GUI Applications for LaTeX (WYSIWYM)?

For those who do not want to memorize syntax and commands, a few applications with GUI can produce LaTeX documents,


Among the above, only LyX is free with a GPL license. Wikipedia has a comparison page for TeX editor.  

Thursday, September 12, 2013

Emulating LaTeX Look & Feel in Microsoft World

Following the instruction , you can find a Word template and the URL to Computer Modern fonts that should be used along with the template.

Using the template and the fonts, you can generate Word documents that remarkable resemble those generated using LaTeX.

I found downloading the fonts manually a pain since there are many. Perhaps, a simpler way is to use a shellscript, which I ran on an Ubuntu Linux guest OS,

wget http://www.ctan.org/tex-archive/fonts/cm/ps-type1/bakoma/ttf/ -O - -q | \
    grep "mirror.*ttf" | \
    sed -e 's/^.*href=\"//g' | \
    sed -e 's/\" title=.*$//g' | \
    xargs wget -c -nv

Well, it may not be a script since it is just a one-liner. If you are unfamiliar with Unix/Linux shells, note that there is no space after "\" that simply indicates a line continuation