Showing posts with label quicktip. Show all posts
Showing posts with label quicktip. Show all posts

Wednesday, August 17, 2022

Recursively Clean LaTeX Debris in all Sub-Folders

 Often, I have a big folder like Lectures/ which may have sub-folders based on topics, and each topic might have additional folders. To clean auxillary LaTeX files in one fell swoop use,

find ./ \( -iname "*.bbl" -o -iname "*.aux" -o -iname "*.log" -o -iname "*.blg" -o -iname "*.nav" -o -iname "*.snm" -o -iname "*.toc" -o -iname "*.vrb" -o -iname "*.out" -o -iname "*.synctex.gz" -o -iname _minted*" \) -delete


Monday, January 20, 2020

QuickTip: Catching array bounds violations in Fortran 90

With gfortran, you can check if array bounds are violated during runtime by,

gfortran -fbounds-check myProg.f90



Friday, October 18, 2019

LaTeX: Cross-referencing between Different Documents

Problem: I have a manuscript TeX file (main.tex), and an independent supporting information file (si.tex). I was to cross-reference (using \label and \ref) items across the two files.

For example, I might want to reference figure 1 from si.tex in main.tex.

Solution: As this SO answer suggests, the answer lies in the CTAN package xr.

In main.tex, just include "si.tex" as an external documents, and all its labels become visible!

\usepackage{xr}
\externaldocument{si}

Thursday, August 22, 2019

QuickTip: Toggling to Previous View in PDF Readers:

I use Preview (on my Mac laptop) and Foxit Reader (on my Linux Desktop) to read PDFs.

While reading papers, I often find myself clicking on links to citations. This takes me to the reference section. After looking up the citation, I like to go back to the previous location on the paper (right before clicking on the link).

How to go back to the "previous view" isn't well documented.

In Preview, the short cut is "Cmd + [" and "Cmd + ]".

In Foxit Reader for Linux (v2.4 and above) the short cut is "Alt + Left Arrow" and "Alt + Right Arrow", respectively. 

Friday, July 5, 2019

QuickTip: Math Font in Matplotlib

Matplotlib (v2 and higher) uses "mathtext" to render math by default. It is quite capable, but I don't like the default font, and prefer the classic "Computer Modern" font.

You can fix this globally by modifying the rc file in your custom-style file (use the command matplotlib.get_configdir() to find location) by adding the line:

mathtext.fontset : cm

If you want to render all text using LaTeX (this slows down rendering somewhat), then use:

text.usetex : true


Tuesday, June 18, 2019

QuickTip: Linux Convert Color PDF to GrayScale

Using GhostScript (source). The first line sets name of output file ("output.pdf" here)

gs \
 -sOutputFile=output.pdf \
 -sDEVICE=pdfwrite \
 -sColorConversionStrategy=Gray \
 -dProcessColorModel=/DeviceGray \
 -dCompatibilityLevel=1.4 \
 -dNOPAUSE \
 -dBATCH \
 input.pdf

Friday, March 15, 2019

QuickTip: LaTeX formatting for SymPy symbols

You can use LaTeX formatting to describe SymPy variables using:

Z, a, Zbar = symbols(r'Z, \alpha, \bar{Z}')

Friday, February 8, 2019

QuickTip: Compare Altered Files in Two Directories

Use case: I copy a directory from my desktop to a USB, change several files while working on it on my laptop or home computer. Now I want to merge it back to the "master" directory on my desktop. I miss a "git diff" like command

On Linux:

diff --brief -r dir1 dir2


Monday, January 21, 2019

QuickTip: Spell Check in LaTeX

On a previous blog, I wrote about how to set up "hunspell" as the default spell-checker in TeXMaker (my LaTeX editor of choice).

One can also spell check non-interactively from the command line. Get the linux utility hunspell using for example,

sudo apt-get install hunspell

Then, to get a list of flagged words that ignore latex tags:

hunspell -l -t myTexDoc.tex | sort

Drop the sort and "-l" flag check spellings interactively.

Tuesday, June 26, 2018

QuickTip: Split Single Column into Multiple Columns

Consider a single column file which begins with

$ cat file.txt
1
yes
single
125K
no
2
no
married
100K
no
...

Suppose you want to split it into 5 columns so that it looks like

1 yes single 125K no
2 no married 100K no
...

You can use either,

$ xargs -n5 < file.txt

or if you want some control over the delimiter

$ paste - - - - - -d, < file.txt

1,yes,single,125K,no
2,no,married,100K,no


Thursday, February 23, 2017

Split a Text File using csplit

Suppose you have a large "sectioned" text file which looks like the following

> cat bigfile.txt
data1
1
2
3

data2
11
22
33

...

csplit bigfile.txt /data/ {*}

splits it into a bunch of files xx0, xx1, xx2, ..., where each of the "xx" files holds a section. Thus,

> cat xx1
data1
1
2
3

and so on. Can be just the quick tool you need at times.