Featured

Use latexdiff to compare different versions of LaTeX tex files to visually mark differences

This post introduces how to use latexdiff to compare two versions of latex *.tex files, in order to visually mark changes to tex files.

(One colleague asked me about the usage of latexdiff, so I think it is a good time to write it up into a blog post to share with those who need some help with this.)

latexdiff is a Perl script and requires an installation of Perl 5.8 or higher.

Use latexdiff to mark differences and create a new LaTeX document with markup differences between two latex files.

  • Linux (Ubuntu) users

latexdiff can be found in Ubuntu repository and detailed description of usage can be found here.

In your terminal, issue the commands below to install latexdiff.

sudo apt-get update
sudo apt-get install latexdiff
# open your terminal, and cd to the tex files you need to compare
# issue the following command
latexdiff original_version.tex revised_version.tex > diff.tex

Run the diff.tex file like you run a normal tex file, you will see beautifully marked differences in the pdf file.

  • Mac OS X users
latexdiff is a Perl script and requires an installation of Perl 5.8 or higher.
Mac OS X includes an installation of Perl and no additional setup is required. latexdiff can be found in any CTAN repository
(If you are using MacTex on your mac,  latexdiff is already installed in MacTex under /usr/texbin/latexdiff. No need to install it separately. To use latexdiff in commend line, see below)
After you setting perl and latexdiff, just open your terminal, and cd to the path where you put you two versions of latex tex files, and then issue the command. (If the two tex files are located in different location, you can just give the relative path to that location for each version of tex file.)

 

$ latexdiff original_version.tex revised_version.tex > diff.tex
will compare original_version.tex to revised_version.tex and create a new file diff.tex showing the differences.
Run the diff.tex file like you run a normal tex file, you will see beautifully marked differences in the pdf file.
  • Online latexdiff 
when you get the diff.tex on the online latexdiff, you can paste into a new tex file and then you can run it and you will see the pdf which shows the differences.
  • Multiple tex files for each version

If each version of your text files contains multiple (sub) tex files or if you want to use latexdiff with Git, check the reference lists for potential solutions.

References:

LATEXDIFF: SUPERB DIFF TOOL FOR LATEX (pdf) — talks about solutions to multiple files, but this can only deal with sub-files on the same level, not nested cases.

Two LaTeX gems: ShareLaTeX and latexdiff (pdf)

Using Latexdiff For Marking Changes To Tex Documents (pdf)

Multiple-file LaTeX diff (pdf— this one is very good. – use python code to merge multiple tex files to one big tex file for each version and then use latexdiff to make comparision.

Latexdiff with subfiles (pdf) — this one talks about solutions to multiple tex files.

Using latexdiff with git (pdf) – Git Latexdiff  — this is about using git together with latexdiff

Git and latexdiff: compare versions of LaTeX documents (pdf) — this is also about using git together with latexdiff

 

 

 

[LaTeX] subfigures with captions

This post provides Latex code examples for how to generate sub-figures with and without captions.

  • Sub-figures with captions
\documentclass{article}
\usepackage{graphicx, caption, subcaption}
\begin{document}
  This article is about ....

\begin{figure}
 \begin{subfigure}{0.96\textwidth} 
     \includegraphics[width=\textwidth]{subfig1} 
     \caption{subfig 1 caption text here}
 \end{subfigure} 
 \centering  %note: this centering command applies to subfig1
 \hfill
 \begin{subfigure}{0.47\textwidth}
     \includegraphics[width=\textwidth]{subfig2}
     \caption{subfig 2 caption text here}
 \end{subfigure}
 \hfill
 \begin{subfigure}{0.47\textwidth}
     \includegraphics[width=\textwidth]{subfig3}
     \caption{subfig 3 caption text here}
 \end{subfigure}
 \caption{the overall fig caption text here}
 \label{fig:subfig_example} % Give a unique label
\end{figure}

\end{document}
  • Sub-figures without caption
\documentclass{article}
\usepackage{graphicx}
\begin{document}
  This article is about ....

%*For figures without sub-captions
\begin{figure}
    \includegraphics[width=0.96\textwidth]{subfig1}
    \centering 
    \hfill
    \includegraphics[width=.48\textwidth]{subfig2} 
    \hfill
    \includegraphics[width=.48\textwidth]{subfig3}
    % figure caption is below the figure
    \caption{figure caption text here}
 \label{fig:subfig_example2} % Give a unique label
 \end{figure}
 
\end{document}

Install DB Browser for SQLite on Ubuntu 16.04

This post introduces how to install DB Browser for SQLite on Ubuntu 16.04.

For Ubuntu and derivaties, @deepsidhu1313 provides a PPA with the latest release at here:

https://launchpad.net/~linuxgndu/+archive/ubuntu/sqlitebrowser

Step 1: Add the PPA shown above by issuing the following command in your terminal:

$ sudo add-apt-repository -y ppa:linuxgndu/sqlitebrowser

Step 2: Update the cache using:

$ sudo apt-get update

Step 3: Install the DB Browser for SQLite package by issuing the following command:

$ sudo apt-get install sqlitebrowser

 

Reference:

http://sqlitebrowser.org/

[LaTeX] Add appendices in an article

This post introduces how to add appendices to an article.

The command \appendix  is included in all basic class files, so you do not need to include any extra package to add appendix, unless the journal that you aim at has specific appendix style requirements.

\begin{document}

\section{Your section name here}
\section{Your section name here}

% Activate the appendix in the doc
% from here on sections are numerated with capital letters 
\appendix

\section{Appendix A title here}
\subsection{Appendix subsection title here}
\subsection{Appendix subsection  title here}

\section{Appendix B title here}

\end{document}

VPN setup on Ubuntu 16.04 (using Cisco AnyConnect client)

This post introduces how to setup VPN on Ubuntu  16.04 LTS using Cisco AnyConnect Client.

Step 1:  Download Cisco AnyConnect client.

Penn Stater can download at here.

Step 2: Extract the file(s) and install as root.

(1) extract the downloaded file;

(2) then cd to the extracted directory where it has an installation .sh file;

(3) then issue the following command to install Cisco AnyConnect Client:

$sudo ./AnyConnectInstall.sh 

# note your .sh file may have slight different name

Step 3:  Run the following command.

$ sudo apt-get install openconnect network-manager-openconnect-gnome

We need to issue this command to  show Cisco Compatible VPN in the list when we open network manager and add a new VPN.

Step 4:  Open Network Manager.

 

Step 5: Add a VPN in the Network Manager

Step6:  Choose Cisco AnyConnect Compatible VPN (openconnect) and click Create.

Step 7: Enter the following info

  • Connection name: Tech Services VPN [Note you can name this as you wish]
  • Gateway: vpn.its.psu.edu  [type in your vpn accordinly]

Click Save.

Step 8: Open Cisco Anyconnect client

Type your VPN address in the connect to textbox, and then enter your username and psw.

Then you are ready to go:)

 

References:

VPN, CISCO AnyConnect, Linux

Cisco VPN client on Ubuntu 16.04 LTS

 

 

 

Two ways to merge PDF files on Mac (GUI and command line)

This post introduces how to merge PDF files on Mac from GUI and from Terminal on Mac OS.

(For Ubuntu and Windows users, check out my post here for solutions.)

Method 1: GUI — using Preview  that comes with your Mac OS.

Check here for how to combine PDFs and reorder, rotate, and delete pages. If the page is not accessible, check the pdf I linked to in the references.

Method 2: From Terminal

We will introduce using gs command.

many people may already have gs package  installed and are already using gs.

TO check whether your Mac has gs installed,  in your terminal, issue the following command:

$ which gs

If you see something like this “/usr/local/bin/gs”, you OS has gs installed

If you see something like “… command not found”, you will need to install gs first.

You can use brew to install it.

$ brew install gs

If you do not have brew installed, check: Install Homebrew.

After you have gs installed,

in your terminal, cd to the directory where the pdf files you want to merge are located, and then issue the following command:

$ gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=merged.pdf source1.pdf source2.pdf source3.pdf

Then you will see a merged.pdf appear in the same folder where you source pdfs are.

Note: You may encounter these two errors in your terminal after your issue the pdf merge command I mentioned above, but be assured, the merge.pdf is correct. you can double check if you are worried about that:)

 

References:

Use Preview to combine PDFs on your Mac (pdf)

How can I combine multiple PDFs using the command line?

 

Read the first line of a file from terminal (on Ubuntu and Mac)

This post introduces how to read the first line of a file from terminal. It works on both Linux (Ubuntu) and Mac OS.

Note: you do not need to install anything, it is built-in on your Ubuntu/Mac OS.

Step 1: open a terminal 

Step 2: cd to the directory where your file (e.g., .txt file) is located 

Step 3: issue the following command

$ head -n 1 example.txt  
# this will read and print the first line of the file in the terminal

$ head -n 2 example.txt 
# this will read and print the first two lines of the file ... you got the idea...

***********************************************

Analogously, see the following command for displaying the last line of a file from terminal:

$ tail -n 1 example.txt # this will read and print the last line of the file in the terminal 

$ tail -n 2 example.txt # this will read and print the last two lines of the file ... you got the idea...

Word count in pdf using wc command (on Ubuntu and Mac)

This post introduces how to count the number of words in a pdf file using wc command. It works on both Linux (Ubuntu) and Mac OS.

Note: you do not need to install anything, it is built-in on your Ubuntu/Mac OS.

Step 1: open a terminal 

Step 2: cd to the directory where your pdf file is located 

Step 3: issue the following command

$ ps2ascii example.pdf | wc -w

Step 4: Then you should see the number of words in that example.pdf

 

P.S.   the wc command has several arguments, see below.

wc -l: print the number of lines in a file.

wc -w: print the number of words in a file.

wc -c: print the number of bytes in a file.

wc -m: print the number of characters from a file.

wc -L: print only the length of the longest line in a file.

 

 

 

[LaTeX] Optional parameters explained for fine tuning the placement of tables and figures in LaTeX

This post introduces the optional parameters to fine tune the placement of tables and figures in LaTeX.

If you are using LaTeX, you have seen figure examples like the following

\begin{figure}[ht]
...
\end{figure}

These are optional parameters to fine tune the placement of tables and figures, the term is Float placement specifiers (introduced in detail below). LaTeX will try to honor the placement with respect to the actual place, the top or bottom of the page, or a separate page of floats coming immediately after the present insertion point.

Float placement specifiers

To direct a float to be placed into one of these areas, a float placement specifier has to be provided as an optional argument to the float.

If no such optional argument is given then a default placement specifier is used, which depends on the float class. Each float in LaTeX belongs to a class. By default, LaTeX knows about two classes,figureand table. A float placement specifier can contain the following characters in any order and combination:

  • ! — indicates that some restrictions should be ignored 
  • h — indicates that the float is allowed to be placed inline (i.e., here)
  • t — indicates that the float is allowed to go into a top area
  • b — indicates that the float is allowed to go into a bottom area
  • p — indicates the the float is allowed to go on a float page or column area

The order in which these characters are stated does NOT influence how the algorithm tries to place the float (e.g., [ht] or [th] will make no difference)! This is one of the common misunderstandings, for instance when people think that bt means that the bottom area should be tried first. You may also force LaTeX to “insist” on these specifications by adding an exclamation mark (!) before the placement parameters, e.g. \begin{figure}[!htb].

However, if a letter is not present then the corresponding area will not be tried at all.

For more detailed intro about this topic, check out How to influence the position of float environments like figure and table in LaTeX?

 

References:

 

How to remove the double quotes in a CSV file on Ubuntu

This post introduces the simplest way to remove all double quotes in a csv file on Ubuntu (via terminal).

If you have a CSV file like

#input.csv
"1,2,3,4,9"
"1,2,3,6,24"
"1,2,6,8,28"
"1,2,4,6,30"

and want something like

#output.csv
1,2,3,4,9
1,2,3,6,24
1,2,6,8,28
1,2,4,6,30

Or you have something like this

and want something like this

In your terminal,

cd to the directory where input.csv file is located and then issue the following command:

$ tr -d '"' <input.csv> output.csv

Note: tr stands for translateThe d flag causes tr command to delete all tokens of the specified set of characters from its input.  

References:

8 Linux TR Command Examples (pdf)

tr (Unix)

How to install Visual Studio Code text editor on Ubuntu 16.04

This post introduces how to install the nice text editor Visual Studio Code on Ubuntu.

Step 1: Install gdebi

Open a terminal and type the following command into your terminal.

$ sudo apt-get install gdebi
# use gdebi tool to install external *.deb packages like Visual Studio Code and Google Chrome.
# gdebi will automatically fetch and install all Visual Studio Code dependencies.

Step 2: Download Visual Studio Code

 

In your terminal, cd to the directory where you downloaded the file (for example, in my case, it is in my Downloads folder.)

Step 3: Install Visual Studio Code

$ sudo gdebi code_1.15.1-1502903936_amd64.deb
# your downloaded version might be different from mine, so change it to #your .deb file

Step 4: Click “Search your computer” icon on your tool bar, and type in Visual Studio Code, you will see it’s installed on your Ubuntu.

Step 5: Right click the Visual Studio Code icon on your tool bar and pick Lock to Launcher, your are ready to use your Visual Studio Code editor on your Ubuntu 16.04:)