                   (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

            ;; see `org-latex-compiler'.  If the document compiler is not in the
            ;; list, and the list is non-nil, the package will not be inserted
            ;; in the final document.
            (setq org-latex-packages-alist
                  '(
                    ;; % 0 paragraph indent, adds vertical space between paragraphs
                    ;; http://en.wikibooks.org/wiki/LaTeX/Paragraph_Formatting
                    ("" "parskip")
                    ;; Graphics package for more complicated figures
                    ("" "tikz")
                    ("" "caption")
                    ;;
                    ;; Packages suggested to be added for previewing latex fragments
                    ;; http://orgmode.org/worg/org-tutorials/org-latex-preview.html
                    ("mathscr" "eucal")
                    ("" "latexsym")))

            ;; Prevent tables/figures from one section to float into another section
            ;; http://tex.stackexchange.com/a/282/52678
            (add-to-list 'org-latex-packages-alist '("section" "placeins"))

            ;; Prevent an image from floating to a different location
            ;; http://tex.stackexchange.com/a/8633/52678
            (add-to-list 'org-latex-packages-alist '("" "float"))
            ;; "H" option is from the `float' package.
            ;; That prevents the images from floating around.
            (setq org-latex-default-figure-position "H") ; figures are NOT floating
            ;; (setq org-latex-default-figure-position "htb") ; default - figures are floating

            (if modi/ox-latex-use-minted
                ;; using minted

;; Time-stamp: <2016-02-12 17:44:54 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

