                   (defvar latex-minted-cachedir (concat temporary-file-directory
                                                         (getenv "USER")
                                                         "/.minted/\\jobname"))
-                  ;; If `org-latex-create-formula-image-program' is set to
-                  ;; `dvipng', minted package cannot be used to show latex
-                  ;; previews.
-                  (add-to-list 'org-latex-packages-alist
+                  ;; `minted' package needed to be loaded AFTER `hyperref'.
+                  ;; http://tex.stackexchange.com/a/19586/52678
+                  (add-to-list 'modi/org-latex-packages-alist-post-hyperref
                                `(,(concat "cachedir=" ; options
                                           latex-minted-cachedir)
                                  "minted" ; package
+                                 ;; If `org-latex-create-formula-image-program'
+                                 ;; is set to `dvipng', minted package cannot be
+                                 ;; used to show latex previews.
                                  ,(not (eq org-latex-create-formula-image-program 'dvipng)))) ; snippet-flag
 
                   ;; minted package options (applied to embedded source codes)
                   (setq org-latex-minted-options
                         '(("linenos")
-                          ("numbersep"   "5pt")
-                          ("frame"       "none") ; box frame is created by the mdframed package
-                          ("framesep"    "2mm")
-                          ;; ("fontfamily"  "zi4") ; required only when using pdflatex
-                                        ; instead of xelatex
-                          ;; At least minted 2.0 required for `breaklines'
-                          ("breaklines") ; line wrapping within code blocks
-                          )))
+                          ("numbersep" "5pt")
+                          ("frame"     "none") ; box frame is created by `mdframed' package
+                          ("framesep"  "2mm")
+                          ;; minted 2.0+ required for `breaklines'
+                          ("breaklines"))) ; line wrapping within code blocks
+                  (when (equal org-latex-compiler "pdflatex")
+                    (add-to-list 'org-latex-minted-options '(("fontfamily"  "zi4")))))
               ;; not using minted
               (progn
-                (add-to-list 'org-latex-packages-alist '("" "listings"))
                 ;; Commented out below because it clashes with `placeins' package
-                ;; (add-to-list 'org-latex-packages-alist '("" "color"))
-                ))
+                ;; (add-to-list 'modi/org-latex-packages-alist-post-hyperref '("" "color"))
+                (add-to-list 'modi/org-latex-packages-alist-post-hyperref '("" "listings"))))
+
+            (setq org-latex-packages-alist
+                  (append modi/org-latex-packages-alist-pre-hyperref
+                          '(("" "hyperref" nil))
+                          modi/org-latex-packages-alist-post-hyperref))
+
+            ;; `-shell-escape' is required when using the `minted' package
 
             ;; http://orgmode.org/worg/org-faq.html#using-xelatex-for-pdf-export
             ;; latexmk runs pdflatex/xelatex (whatever is specified) multiple times

;; Time-stamp: <2016-02-11 18:37:04 kmodi>
;; Hi-lock: (("\\(^;\\{3,\\}\\)\\( *.*\\)" (1 'org-hide prepend) (2 '(:inherit org-level-1 :height 1.3 :weight bold :overline t :underline t) prepend)))
;; Hi-Lock: end


            ;; (setq org-latex-create-formula-image-program 'dvipng) ; NOT Recommended
            (setq org-latex-create-formula-image-program 'imagemagick) ; Recommended

            ;; Controlling the order of loading certain packages w.r.t. `hyperref'
            ;; http://tex.stackexchange.com/a/1868/52678
            ;; ftp://ftp.ctan.org/tex-archive/macros/latex/contrib/hyperref/README.pdf
            ;; Remove the list element in `org-latex-default-packages-alist'.
            ;; that has '("hyperref" nil) as its cdr.
            ;; http://stackoverflow.com/a/9813211/1219634
            (setq org-latex-default-packages-alist
                  (delq (rassoc '("hyperref" nil) org-latex-default-packages-alist)
                        org-latex-default-packages-alist))
            ;; `hyperref' will be added again later in `org-latex-packages-alist'
            ;; in the correct order.

            ;; The `org-latex-packages-alist' will output tex files with
            ;;   \usepackage[FIRST STRING IF NON-EMPTY]{SECOND STRING}
            ;; It is a list of cells of the format:
            ;;   ("options" "package" SNIPPET-FLAG COMPILERS)
            ;; If SNIPPET-FLAG is non-nil, the package also needs to be included
            ;; when compiling LaTeX snippets into images for inclusion into
