# Rubab's blog

The world of smartphones and PC from my angle

# My Trips and Tricks with LaTeX

There were some useful things that I recently found that one can do with LaTeX so I decided to share here.

Note: I used the default compilation engine (pdfLaTeX+MakeIndex+BibTeX) of MiKTeX TeXworks

1.  Merge multiple .pdf files into one

Previously, I used to depend upon the online pdf merging tools. It used to mess up the quality of the documents and I used to have some Internet insecurities as well when it comes to confidential documents being uploaded online for conversion purpose.

You can create a new TeX document and copy & paste the following commands:

\documentclass[a4paper]{article}

\usepackage{pdfpages}

\begin{document}

\includepdf[pages=-]{file1.pdf}

\includepdf[pages=-]{file2.pdf}

\includepdf[pages=-]{file3.pdf}

\end{document}

Replace the {file1.pdf}, {file2.pdf} and {file3.pdf} command with the exact names of your file. You can of course merge more files; just repeat the \includedpdf command again. Press the Play/Compile button. It will automatically install the package pdfpages. Make sure your all .pdf files are in the same folder as the .tex file.

2. Extract a page from a pdf file

This tool comes in handy sometimes and again no loss of quality.

Just create a new TeX document and copy & paste the following commands:

\documentclass[a4paper]{article}

\usepackage{pdfpages}

\begin{document}

\includepdf[pages=2]{file1.pdf}

\includepdf[pages=5]{file1.pdf}

\end{document}

Replace the {file1.pdf} command with your desired file name and [pages=2] or [pages=5] with your desired page/s number for extraction. Press the Play/Compile button. It will automatically install the package pdfpages. Make sure your .pdf file is in the same folder as the .tex file.

3. Convert image file (.png/.jpg/etc.) to .pdf file

I was so pleased when I found that LaTeX can convert pictures into .pdf documents. No extra margins are added which is a bonus. You can either convert the size as the source or you can customize the picture’s size/dimensions in the output .pdf file.

Create a new TeX document and copy & paste the following commands:

\documentclass{standalone}

\usepackage{graphicx}

\begin{document}

\includegraphics[width=320mm,height=450mm]{file1.png}

\end{document}

Replace the {file1.png} command with your desired file name and customize the dimensions [width=320mm,height=450mm] with your own desire. In case you want the size of the image as it is then delete the [width=320mm,height=450mm] command. Press the Play/Compile button. It will automatically install the package graphicx. Make sure your picture file is in the same folder as the .tex file.

…….to be continued.