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

 

 

 

Dynamic GPU usage monitoring (CUDA)

To dynamically  monitor NVIDIA GPU usage,

in your terminal, issue the following command:

$ watch -n 1 nvidia-smi

It will continually update the gpu usage info (every second, you can change the 1 to 2 or the time interval you want the usage info to be updated).

For more commonly used Linux commands, check my other posts at here  and here .

Unzip file from Terminal on Linux

This post provides the instructions about how to unzip a file from terminal on Linux.

Step 1: install unzip using the following command

$ sudo apt-get install unzip

Step2: cd to the directory where you zip file located

Step3:  use  the following command to unzip your file

$ unzip yourfile.zip 

#this will unzip the file to the current folder
#if you'd like to extract to a particular destination folder, use the following instead:
$ unzip yourfile.zip -d destination_folder

For more commonly used Linux commands, check my other posts at here  and here .

Counting files in a Linux directory

This post will show you how to count files under a Linux directory.

Step 1: cd  to the folder you would like to count the files.

Step 2: issue the following command, then you should see a number, which is the number count of the files under the current directory.

find . -type f | wc -l
  • -type f indicates  counting files only.   You can remove the -type f to include directories (and symlinks) while counting.
  • | (note: not ¦) redirects find command’s standard output to wc command’s standard input.
  • wc (stands for word count) counts newlines, words, and bytes on its input (see here for more details.).
  • -l to count just newlines.

Notes:

  • This command may overcount if filenames can contain newline characters.

For more commonly used Linux commands, check my other posts at here  and here .

List files by time (in reverse order) and in human readable file size

This post tells you how to list files under a directory by time in reverser order and in human readable file size (works on Linux OS and Mac).

  • ls -ltrh 

list all the csv files under the current directory in long format by time and in reverse order, the file size in human readable format (e.g., in mb, or gb, instead of byte size)

  • -l List in long format. If the output is to a terminal, a total sum for all the file sizes is output on a line before the long listing.
  • -r Reverse the order of the sort to get reverse lexicographical order or the oldest entries first (or largest files last, if combined with sort by size.
  • -t Sort by time modified (most recently modified first) before sorting the operands by lexicographical order.
  • ls -ltrh *.csv

list all the csv files under the current directory in long format by time and in reverse order, the file size in human readable format (e.g., in mb, or gb, instead of byte size)

 

For more commonly used Linux commands, check my other posts at here  and here .

Ubuntu command line check disk usage

To check hard disk usage on Ubuntu from a terminal (command line), issue the following command  in your terminal.

liping:~$ df -h

-h stands for human which makes it readable by us humans, otherwise the file size will be in bytes:)

After you issue the command, you would  see your disk usage similar to the info given below.

Filesystem            Size  Used Avail Use% Mounted on
/dev/sda7              68G   23G   43G  35% /
udev                   10M     0   10M   0% /dev
tmpfs                 800M  1.6M  798M   1% /run
tmpfs                 5.0M     0  5.0M   0% /run/lock
/dev/sda6             264G  173G   78G  69% /home
tmpfs                 3.2G  992K  3.2G   1% /tmp
.
.
.

For more commonly used Linux commands, check my other posts at here  and here .

[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