Miscellaneous

Some (maybe) useful tools

Create booklet from PDF

Use pdfbook2:

pdfbook2 --paper=a4paper --inner-margin=100 file.pdf

You can use options for the --out-margin as well as for top and bottom. Note: if you preview the output pdf, odd pages will be upside-down. That’s what you want if your print settings are Two sided: Long Edge (Standard), Pages per side: 1.

Increase contrast in a PDF

Convert PDF pages to individual images

convert -density 600 your_pdf_filename.pdf  output-%02d.jpg

Adjust image quality

convert output*.jpg -normalize -threshold 80% final-%02d.jpg

If you want a pdf back:

convert final*.jpg my_new_highcontrast.pdf

See superuser.com for more links and comments.

Compress (multiple) images

To compress one image:

convert image.jpg -quality 50% image-compressed.jpg

To compress all images in the folder where you are (output of pwd)

for i in *; do convert $i -quality 50% $i-out.jpg ; done;

See askubuntu.

Compress PDF

Assuming that these are PDF containing only large images, this works well:

ps2pdf -dPDFSETTINGS=/ebook input.pdf output.pdf

The other options for dPDFSETTINGS are: /screen lower quality, smaller size. (72 dpi)

/ebook for better quality, but slightly larger pdfs (150 dpi)

/prepress output similar to Acrobat Distiller “Prepress Optimized” setting (300 dpi)

/printer selects output similar to the Acrobat Distiller “Print Optimized” setting (300 dpi)

/default selects output intended to be useful across a wide variety of uses (possibly larger output)

Grayscale output

To generate a PDF in grayscale (useful for printing) in $\LaTeX$

\usepackage{xcolor}             % for output 
\selectcolormodel{gray}         % in grayscale 

Note: external figures will stay in their original colour. See TeXstackexchange and latex.org.

Break display equations on multiple pages

Use the command \allowdisplaybreaks, see this for more options.

The environments split and aligned should prevent a block from page breaks.

biblatex/biber

You can keep your bibliography in a single .bib file in a separated repository, and include it via git submodule in each of your project. Here are some reasons for which you may wish to do so.

biber supports multiple keys: they are called IDS, see this question.

latexdiff-git

Generate a PDF to view diff on LaTeX source between commits. For example:

latexdiff-git --revision e26bbec file.tex

where you want to replace e26bbec with your commit hash.

Use --flatten if you are including other sources with \input or \include in your TeX.


git

git: compare two commits

Run git show to see the difference between HEAD and the last commit. Run

git diff HEAD~3        (diff between working tree  and the last 3 commits)
git diff HEAD~3 HEAD   (diff between     HEAD      and the last 3 commits)

Note: git show = last commit log + git diff HEAD~1 HEAD. Use

git show HEAD file.tex

to show the difference for a single file. See stackoverflow


git: compare two files in different branches

git diff branch1 branch2 myfile.cs

As suggested in stackoverflow.


git: history of a file

git log -p -- file.tex

git: history around a line

For the chunk of lines: 313 – 316 for example:

git log --topo-order --graph -u -L313,316:file.tex

git: rebasing

To rebase a branch onto master, first checkout the branch

git checkout brach_to_rebase

from there, tell git where to rebase it, for example:

git rebase master

To rebase interactively the last 2 commits (from HEAD), or to squash the last commit

git rebase -i HEAD~2

git: pull & rebase

To pull and rebase your recents commits on top:

git pull origin --rebase

Set this by default via: git config --global pull.rebase true. There are several merging strategies, the most common are: resolve, recursive and octopus.🐙


git: worktree

Add a new worktree tracking an existing remote branch:

git worktree add <path> <remote>/<branch>

Use -b <new_branch> to track the worktree in a local branch. See my answer on stackexchange.


git: delete remote branch

Simply git push with a -d flag, then specify the name of the remote branch:

git push -d origin branch

TableMode

Tables in Emacs

Run: M-x table-insert and fill the table. When you are done, use M-x table-generate-source to generate code in HTML, LaTeX, Wiki and Mediawiki, and more.


Magit

Use git inside Emacs.

Run: M-x magit-status to see git status. From the status buffer you can:

  • stage files with s , or with M-x magit-stage-file
  • commit your changes with c c (type the message then C-c C-c to actually commit),
  • do a git push P u or a git pull F u.

Rebase commits marked with !squash automatically with M-x magit-rebase-autosquash.

You can use F – (“Instant Fixup”) to performs a rebase after creating the !fixup commit. See emacs.stackexchage


Emerge

Merge two file in Emacs.

Run: M-x emerge-files and choose the two files. Then use the following shortcuts:

  • Next difference with n,
  • Previous difference with p

For a difference, you can choose: the A version (left) with a and the B version (right) with b.

Use q to quit and then save the merge (buffer) in a file.


Convert

Pandoc

Convert epub in PDF.

pandoc -f epub -t latex --latex-engine=xelatex file.epub -o file.pdf

Other format and options in the manual.

Convert multiple files

for f in /path/*.jpg /path/*.JPG; do
    convert "$f" "${f%.*}.gif"
done
See askubuntu

Convert doc to pdf

lowriter --convert-to pdf file.doc

See askubuntu

Convert SVG to PDF

Use Inkscape in a shell:

inkscape file.svg --export-area-drawing --batch-process --export-type=pdf --export-filename=output.pdf

See graphicdesign.stackexchange.

Convert SVG to TeX

Include it directly as explained here or use Inkscape in a shell:

inkscape -D -z --file=image.svg --export-pdf=image.pdf --export-latex

See tex.stackexchange.


rsync

Sync a local folder with a remote one. ( See unix.stackexchange )

rsync -auv "source_folder/" "user@<source>:<dest_dir>/"

Copy files for backup.

rsync -gloptrunc $srcdir $dstdir

A brief guide, from serverfault.com:

  • g - preserve group ownership info
  • l - copy symlinks as symlinks
  • o - preserve owner info
  • p - preserve permissions
  • t - preserve timestamps
  • r - recurse thru directories
  • u - update, skip any newer files
  • [n] - no, dont do this, do a dry run instead
  • c - checksum, attempt checksums on file blocks when possible (*) note: on local filesystems, this get overridden and entire files are copied instead.
  • v - verbose

Change PDF metadata

From command line:

exiftool -Title="This is the Title" -Author="Happy Man" -overwrite_original file.pdf

See askubuntu. My friend Andrea had developed a user friendly GUI for this task.

Roughly count words in a PDF

pdftotext myfile.pdf - | wc -w

See this question on superuser for more options.

Count words in a $\TeX$ or $\LaTeX$ file

Use texcount:

texcount -1 -sum -inc file.tex
  • -inc to parse files called with \include and \input,
  • -sum to show the total
  • -1: Same as specifying -brief and -total, to ensure only one output line. Used with -sum to print the total number only.

See the texcount manual.

Include SVG into TeX

Use the svg package and compile with the option --shell-escape to run Inkscape during compilation.

\usepackage{svg}
[...]
\begin{figure}[tbh]
    \centering
    \includesvg[scale=1.2]{test-svg}
    \caption{Included SVG file}\label{fig:testsvg}
\end{figure}
See stackoverflow.

Placement options with LaTeX figures

The order does not matter.

  • h means here (if there is enough room left on the page)
  • t means top: Place it at the top of a page.
  • b means bottom: Place it at the bottom of a page.
  • p means page: Place it on a page containing only floats, such as figures and tables.
  • ! allows to ignore certain parameters of LaTeX for float placement.

See more on TeX.stackexhange.

Maths symbols in unicode in table of content (toc)

To render maths symbols in section titles, you can use \texorpdfstring :

\texorpdfstring{TeX command}{PDF string you want}

For example: \section{The \texorpdfstring{$(\mu, W)$}{(μ,W)} manifold $M$}.


See also Pavel Zorin-Kranich page about $\LaTeX$ tools and best practice

Suggestions on How to write maths.

Other useful tools


reMarkable

Scripts for the reMarkable are here


This website is powered by HUGO with the minimal-bootstrap-hugo-theme.