References/Windoze + Emacs + LaTeX

Table of Contents

Every Modern Man Should Learn how to Use Emacs

Emacs is a great tool for text editing, further it can be used for genereal writing.

Why Emacs?

In a nutshell: emacs is arguably the most powerful editor on earth.

More details: The emacs key bindings are widely used in other applications. For example, terminals on Linux/Mac support emacs-like navigation; Matlab also ships a built-in emacs keyboard shortcut.

Popular IDEs such as Android Studio also has key map for emacs.

We should bear in mind though, the point of inventing good editors is to speed up writing. Our focus therefore should be writing in the same way as automobiles were invented to speed up commuting and we never turn our attention to luxury cars.

The Set-up

winematex = Win doze + Ema cs + La TeX, a compromise for people stuck on Windoze machines to use emacs.

Originally the portable set-up was created for light use in ECE 486 Lab, it now can be updated to the latest release of emacs (26.1 as of 28 May, 2018), and with more advanced features enabled such as

  • gnus for emails
  • org for
    • exporting HTML and
    • personal planning
  • Spell checking with multi dictionaries

Requirements:

winematex Folder Structure

The overview of the winematex folder structure is as follows. (d) stands for a folder.

winematex(d) --+-- emacs26(d) -------+-- .emacs.d(d) --+-- ...
               |                     +-- ...           +-- elpa(d) --> packages           
               |                     +-- .emacs 
               |                     +-- emacs_launch.bat
               |                     +-- matlabshell.cmd
               |                     +-- matlabShell.exe
               |                      
               +-- GnuPG228(d) ------+-- bin(d) -------+-- ...
               |                     +-- ...           +-- gpgconf.ctl
               |                                     
               +-- hunspell1323(d) --+-- ...         
               |                     +-- share(d) -----+-- hunspell(d) --> dicts
               |                     +-- ...           +-- ...
               |
               +-- miktex29(d) ------+-- ...
               |                     +-- ... 
               | 
               +-- SumatraPDF312(d) -+-- ...
                                     +-- ...

README File

The original readme file was written for ECE 486 Lab where we are forced to use Micro$oft Windoze. Based on this, we will set up a new working copy of winematex using the latest emacs.

Emacs + LaTeX for ECE 486
=========================

Why emacs?
----------

In a nutshell: emacs is arguably the most powerful editor on earth.

More details: The emacs key bindings are widely used in other applications.
For example, terminals on Linux/Mac support emacs-like navigation; Matlab also
ships a built-in emacs keyboard shortcut.


What is included?
-----------------

Inside N:\labs\ECE486\ece486_Emacs_LaTeX folder:

  - emacs_latex.7z                   (available on lab computers only)
  - signature.sha256                 (available on lab computers only)
  - public_key.pem                   (available on lab computers only)
  - openssl-1.0.2l-i386-win32.zip    (available on lab computers only)
  - Reeeaaaaddddme.txt (this file)   (available on lab computers/github repo)

  Note: Read '_emacs' file in github repo so you can have your own setup.

  https://github.com/yunlhan/ece486lab_latex/blob/master/emacs_latex/_emacs


How to use this?
----------------

(1) Verify 'emacs_latex.7z' package

    The 'emacs_latex.7z' zip has been signed by Yün. You can use openssl to
    verify the package. Follow the steps below,

    (1.1) Start command line prompt and 'cd' to where 'openssl.exe' resides.
          We shipped with this file a zip file for openssl windows binaries.
    (1.2) Issue commands below, modify <pub_key>, <sig_sha256> etc. accordingly.
          (<pub_key> = public_key.pem and <sig_sha256> = signature.sha256)

         # decode signature 
         >openssl.exe base64 -d -in <sig_sha256> -out <tmp_sign.sha256>
         # verify signature
         >openssl.exe dgst -sha256 -verify <pub_key> -signature <tmp_sign.sha256>
          emacs_latex.7z

    (1.3) You should see 'Verified OK' if the package is intact.

    In case the included openssl zip has been tampered, it is available

    https://wiki.openssl.org/index.php/Binaries 
          |
          +--> https://indy.fulgan.com/SSL/

    In case the public key has been tampered, it is posted here

    https://chipnotized.org/ref.html#pub_key

(2) Unpack 'emacs_latex.7z'

    You might need 7-Zip from

    http://www.7-zip.org/7z.html.

    Once 'emacs_latex.7z' is unpacked, you will see four folders:

    - emacs25          (editor)
    - hunspell1323     (spell checker)
    - miktex29         (TeX suite)
    - SumatraPDF312    (PDF viewer)

(3) First use

    No installation is needed. This setup is completely portable and can be used
    on USB flash drives.

    (3.1) (Optional) Go to 'emacs25' folder and rename '_emacs' to '.emacs'.
    (3.2) 'emacs_launch.bat' alongside '_emacs' is the app launcher. Please
          read this file first. You may want to create a desktop shortcut by
          right click --> 'send to desktop'.
    (3.3) Once emacs is up, drag and drop '_emacs' file into emacs window and
          read '_emacs' carefully. It is a detailed how to.


Known setup problems
--------------------

(1) Inverse search feature requires a correctly set value for
    'InverseSearchCmdLine' in 'SumatraPDF-settings.txt' (in 'SumatraPDF312'
    folder).

    InverseSearchCmdLine = "<WHERE>\emacs_latex\emacs25\bin\emacsclientw.exe" -n
    +%l "%f"

    Depending on where you unpacked 7z package, you might want to hard code the
    absolute path for 'emacsclientw.exe'.

    (Fixed. See 'emacs_launch.bat' file.)

(2) On Win 10, similar to problem (1), you might need to hard code where
    'SumatraPDF.exe' is in the '_emacs' file (line 313). Win 7 does not have 
    this problem.

    (Fixed. See '_emacs' file, line 316.)


----
Last updated
08/14/2017

.emacs File

The file itself is a how-to. This file resides in EMACS_ROOT. Sometimes _emacs is used; it is the older naming style but it is not considered a hidden file. (.* is a hidden file in BSD or Linux.)

;;; +------------------------------------------+
;;; | ECE 486 Lab (Day 0: Intro Emacs + LaTeX) |
;;; |                                          |
;;; | by Yün Han                               |
;;; | 2017-08-09 : first release               |
;;; | 2018-06-06 : updated                     | 
;;; |       ^ emacs 26.1                       |
;;; |       ^ gnupg 2.2.7                      |
;;; |       + multi dict support               |
;;; | 2018-06-17 : updated                     |
;;; |       ^ gnupg 2.2.8 security advisory    |
;;; +------------------------------------------+

;;; First of all, reference card for emacs itself. See 
;;; https://www.gnu.org/software/emacs/refcards/pdf/refcard.pdf
;;; 
;;; The most important parts for us are (in that order):
;;;
;;;   - Motion
;;;   - Killing and Deleting
;;;   - Files
;;;   - Spelling Check
;;;   - Getting Help
;;;   - Incremental Search
;;; 
;;; For mode specific refcard, see
;;; https://www.emacswiki.org/emacs/ReferenceCards

;;; Our aim is to have a (lightweight) *portable* setup for writing in LaTeX
;;; on Windows(R) platform:
;;;
;;; 1. Download 'emacs-26.1-x86_64.zip' for 64 bit Windows machines from
;;;    https://ftp.gnu.org/gnu/emacs/windows/
;;;     
;;;    The one with dependences will support advanced features such as secure transport
;;;    emails and many others.
;;; 2. Unpack 'emacs' anywhere you like as long as you have write privilege.
;;; 3. Create a *.bat file like below. As for '%~dp0' expansion, see
;;;    https://stackoverflow.com/a/10290765/1489881
;;;
;;;  +-------------------------------------------------------------------------+
;;;  | rem This is Windows *.bat file for launching portable emacs             |
;;;  | rem Set emacs HOME as current directory                                 |
;;;  | set HOME=%~dp0                                                          |
;;;  | rem Launch emacs. Note '%*' for situations where input args are present |
;;;  | "%~dp0bin\runemacs.exe" %*                                              |
;;;  +-------------------------------------------------------------------------+
;;;
;;;    Line 'set HOME=%~dp0' forces emacs to save config files under the same
;;;    directory as emacs root installation. '%~dp0' expands to a path (p) where
;;;    current batch file resides including drive letter (d). Number '0' refers
;;;    to batch file itself. (Update: See the latest 'emacs_launch.bat'.)
;;;    
;;;  ----> CURRENT FOLDER ./
;;;                       ./EMACS26_ROOT/BIN      ----> SUB FOLDERS
;;;                       ./EMACS26_ROOT/LIB      ----> SUB FOLDERS
;;;                       ./EMACS26_ROOT/...
;;;                       ./EMACS26_ROOT/_EMACS (THIS FILE)
;;;                       ./EMACS26_ROOT/EMACS_LAUNCH.BAT
;;;                       ./...
;;;
;;; 4. Download 'hunspell-1.3.2-3-w32-bin.zip' from 'ezwinport' project, 
;;;    https://sourceforge.net/projects/ezwinports/files/
;;; 5. Unpack 'hunspell' but keep hunspell root under the same folder as
;;;    emacs root, i.e.,
;;; 
;;;  ----> CURRENT FOLDER ./
;;;                       ./EMACS26_ROOT/BIN      ----> SUB FOLDERS
;;;                       ./EMACS26_ROOT/LIB      ----> SUB FOLDERS
;;;                       ./EMACS26_ROOT/...
;;;                       ./HUNSPELL1323_ROOT/BIN ----> SUB FOLDERS
;;;                       ./HUNSPELL1323_ROOT/LIB ----> SUB FOLDERS
;;;                       ./HUNSPELL1323_ROOT/...
;;;                       ./...
;;;
;;; 6. Download 'SumatraPDF-3.1.2-64.zip' (portable) from
;;;    https://www.sumatrapdfreader.org/download-free-pdf-viewer.html
;;; 7. Unpack 'SumatraPDF' but keep sumatrapdf root under the same folder as
;;;    emacs root, i.e.,
;;;  
;;;  ----> CURRENT FOLDER ./
;;;                       ./EMACS26_ROOT/BIN      ----> SUB FOLDERS
;;;                       ./EMACS26_ROOT/LIB      ----> SUB FOLDERS
;;;                       ./EMACS26_ROOT/...
;;;                       ./SUMATRAPDF312_ROOT/SUMATRAPDF.EXE (STANDALONE)
;;;                       ./...
;;; 
;;; 8. Download 'miktex-portable-2.9.xxxx.exe' (portable, 7z self-extract) from
;;;    https://miktex.org/portable
;;; 9. Unpack 'miktex' but keep miktex root under the same folder as emacs
;;;    root, i.e.,
;;;
;;;  ----> CURRENT FOLDER ./
;;;                       ./EMACS26_ROOT/BIN      ----> SUB FOLDERS
;;;                       ./EMACS26_ROOT/LIB      ----> SUB FOLDERS
;;;                       ./EMACS26_ROOT/...
;;;                       ./MIKTEX29_ROOT/MIKTEX-PORTABLE.CMD (BAT FILE)
;;;                       ./MIKTEX29_ROOT/TEXMFS  ----> SUB FOLDERS
;;;                       ./...
;;;
;;; 10. Unpack GnuPG but keep gnupg root under the same folder as emacs root, 
;;;     i.e., 
;;; 
;;;  ----> CURRENT FOLDER ./
;;;                       ./EMACS26_ROOT/BIN      ----> SUB FOLDERS
;;;                       ./EMACS26_ROOT/LIB      ----> SUB FOLDERS
;;;                       ./EMACS26_ROOT/...
;;;                       ./GNUPG_ROOT_ROOT/BIN ----> SUB FOLDERS
;;;                       ./GNUPG_ROOT_ROOT/LIB ----> SUB FOLDERS
;;;                       ./GNUPG_ROOT_ROOT/...
;;;                       ./...
;;;    ____
;;;    Note: To make gnupg portable, assume a folder GnuPG/bin is where 
;;;    ----  'gpgconf.exe' resides. Create an empty file 'gpgconf.ctl' under the
;;;           same directory then GnuPG/bin will be GNUPGHOME, all other 
;;;           methods of setting GNUPGHOME will be ignored.
;;;
;;; 11. Keep reading this file.

;;; Do you know the differences among ';',';;' and ';;;'?
;;; For the answer, see
;;; https://www.gnu.org/software/emacs/manual/html_node/elisp/Comment-Tips.html

;;; Minimum Configuration
;;; ---------------------

(set-language-environment "UTF-8")     ; UTF-8 as default encoding
(column-number-mode 1)                 ; Show column number
(scroll-bar-mode -1)                   ; Don't show scroll bar
(tool-bar-mode -1)                     ; Don't show tool bar
(blink-cursor-mode -1)                 ; Don't blink the cursor
;;; Highlight matching parentheses
(require 'paren)
(show-paren-mode 1)                    ; Highlight matching parentheses
(electric-pair-mode 1)                 ; Auto pair parentheses

(setq visible-bell 1)                  ; Mute emacs beep sound
(setq-default fill-column 80)          ; Paragraph filling/wrapping at col 80
;;; Need to install 'fill-column-indicator'. It draws a thin rule at col 80
;; (require 'fill-column-indicator)    ; Show wrapping rule at col 80
(auto-fill-mode 1)                     ; Auto wrap at line width set at col 80
(global-visual-line-mode 1)            ; Auto wrap, global
;;; See http://geosoft.no/development/emacs.html
(setq default-frame-alist (append (list
                                   '(width  . 95)  ; Width set to 81 characters
                                   '(height . 32)) ; Height set to ~30 lines
                                  default-frame-alist))
(setq inhibit-startup-message   t)     ; Don't want any startup message
(setq make-backup-files         nil)   ; Don't want any backup files
(setq auto-save-list-file-name  nil)   ; Don't want any .saves files
(setq auto-save-default         nil)   ; Don't want any auto saving

(setq search-highlight           t)    ; Highlight search object
(setq query-replace-highlight    t)    ; Highlight query object
(setq mouse-sel-retain-highlight t)    ; Keep mouse highlighting 

;;; Not used when solarized theme installed
;(set-face-background 'region "yellow") ; Set region background color
;(set-background-color        "khaki")  ; Set emacs background color
;;; Load solarized theme upon start instead
(load-theme 'sanityinc-solarized-dark)

;;; Spell Check
;;; -----------

;;; See https://www.emacswiki.org/emacs/InteractiveSpell
;;; and https://lists.gnu.org/archive/html/help-gnu-emacs/2014-04/msg00030.html
(setenv "LANG" "en_US") ; Needed for Windows. Tested on Win 7/10.
;;; 'en_US' is the key for 'hunspell' to search in dictionary path. Dictionaries
;;; are saved in 'HUNSPELL1323_ROOT/share/hunspell'.
(setq ispell-program-name "~/../hunspell1323/bin/hunspell.exe")
(setq ispell-local-dictionary "en_US")
;;; Multi dicts support, see how spell works in manual
;;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Spelling.html

;;; The 'nil' entry in the alist is needed. Originally it was abscent and there was error 
;;; like 'wrong argument listp' 
(setq ispell-local-dictionary-alist '(
                                      (nil  ; change to "hunspell-default" in 26.1
                                       "[[:alpha:]]"
                                       "[^[:alpha:]]"
                                       "[']"
                                       t
                                       ("-d" "en_US")
                                       nil
                                       iso-8859-1)
                                      ("american"
                                       "[[:alpha:]]"
                                       "[^[:alpha:]]"
                                       "[']"
                                       t
                                       ("-d" "en_US") 
                                       nil
                                       utf-8)))

(add-to-list 'ispell-local-dictionary-alist '("deutsch"
                                              "[[:alpha:]ÄÖÜéäöüß]"
                                              "[^[:alpha:]ÄÖÜéäöüß]"
                                              "[']"
                                              t
                                              ("-d" "de_DE_frami") ; Dict file name
                                              nil
                                              iso-8859-1))
(setq ispell-dictionary nil)
(require 'ispell)
;;; ____
;;; Note: Multi-dicts (multi-lang) is possible but that is not our top priority.
;;; ¯¯¯¯
;;; (Added german support)

;;; +--------------------------------------------------------------------------+
;;; | Mini How-to (ispell/hunspell)                                            |
;;; | =============================                                            |
;;; |                                                                          |
;;; | 1. If unsure of a word, move cursor to the word and 'M-$'.               |
;;; | 2. Highlight a block of text then 'M-x ispell-region' is always useful.  |
;;; | 3. See 'Tools -> Spell Checking -> ... ' in the menu bar for other       |
;;; |    options.                                                              |
;;; | 4. 'flyspell' mode can be enabled by 'M-x flyspell-mode'. It can be slow |
;;; |    for large documents. Therefore, on demand usage like methods 1 & 2    |
;;; |    is recommended.                                                       |
;;; | 5. To switch spell check dictionaries, 'M-x ispell-change-dictionary'    |
;;; |    For example, we defined an alias 'deutsch' for german spell checking. |
;;; |    After 'M-x ispell-change-dictionary', type 'deutsch' and enter.       |
;;; +--------------------------------------------------------------------------+

;;; Melpa Package Manager
;;; ---------------------

;;; See https://stable.melpa.org/#/getting-started
(require 'package) ;; You might already have this line
(let* ((no-ssl (and (memq system-type '(windows-nt ms-dos))
                    (not (gnutls-available-p))))
       (url (concat (if no-ssl "http" "https") "://melpa.org/packages/")))
  (add-to-list 'package-archives (cons "melpa" url) t))
(when (< emacs-major-version 24)
  ;; For important compatibility libraries like cl-lib
  (add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/")))
(package-initialize) ;; You might already have this line

;;; Installed packages (excluding dependences): 
;;; - auctex
;;; - auto-complete
;;; - color-theme-sanityinc-solarized
;;; - helm
;;; - org
;;; - org-ac
;;; - htmlize
;;; - w3m

;;; +--------------------------------------------------------------------------+
;;; | Mini How-to (Melpa)                                                      |
;;; | ===================                                                      |
;;; |                                                                          |
;;; | 1. After successful install, type 'package-list-packages' to refresh     |
;;; |    repository list.                                                      |
;;; | 2. Browse the list of packages (1000+, standard emacs navigation         |
;;; |    available), type 'i' to mark new installation, type 'U' to mark       |
;;; |    upgrade, and type'x' to execute. Use 'd' to delete. See more press    |
;;; |    'h'.                                                                  |
;;; |    ____                                                                  |
;;; |    Note: In our case, emacs HOME '~' is just the same as EMACS_ROOT.     |
;;; |    ¯¯¯¯                                                                  |
;;; +--------------------------------------------------------------------------+

;;; Auto-Complete 
;;; -------------

;;; See https://github.com/auto-complete/auto-complete
(ac-config-default)
;;; flyspell workaround; without it, auto-complete will be disabled as soon as 
;;; flyspell is enabled 
(ac-flyspell-workaround) 

;;; LaTeX + SumatraPDF
;;; ------------------

;;; MikTeX binary path
;;; "~/../miktex29/texmfs/install/miktex/bin"
;;; SumatraPDF path
;;; "~/../SumatraPDF312"

;;; Not working, have to set PATH in 'emacs_launch.bat'
;;; Add SumatraPDF and MikTeX folders to PATH and prioritize them.
(setenv "PATH" (concat
                "~/../miktex29/texmfs/install/miktex/bin" ";"
                "~/../SumatraPDF312" ";"
                (getenv "PATH") ";"
                ))
;;; Not working, have to set PATH in 'emacs_launch.bat'
;;; Add SumatraPDF and MikTeX folders to the front of 'exec-path' as well.
;; (setq exec-path (append '(
;;                        "~/../miktex29/texmfs/install/miktex/bin" ";"
;;                        "~/../SumatraPDF312" ";"
;;                        exec-path)))

;;; Install AUCTeX from Melpa then enable 'auctex' mode.
(if (eq system-type 'windows-nt)
    (load "auctex.el" nil t t)
    ;; (load "preview-latex.el" nil t t)
    (require 'tex-mik) ;; Link between AUCTeX and SumatraPDF
)

;;; auto-complete and flyspell are bound the same key, so use the workaround
;; (ac-flyspell-workaround)

;;; Turn on 'ac-math' (see refcard for auctex how to enter symbols or greek
;;; letters quickly). Need to install 'ac-math' package.
;; (require 'ac-math)

;;; Make auto-complete aware of `latex-mode`
(add-to-list 'ac-modes 'latex-mode)   

;;; +--------------------------------------------------------------------------+
;;; | Mini How-to (Inverse Search in SumatraPDF)                               |
;;; | ==========================================                               |
;;; |                                                                          |
;;; | 1. Go to SUMATRAPDF_ROOT and start SumatraPDF.exe.                       |
;;; | 2. Click the menu icon on the top left corner and go to                  |
;;; |    'Settings -> Options'.                                                |
;;; | 3. In 'Set inverse search command-line', enter (with quotes)             |
;;; |   +-----------------------------------------------+                      |
;;; |   | "emacsclientw.exe" -n +%l "%f"                |                      |
;;; |   +-----------------------------------------------+                      |
;;; |    TODO (fixed): At the moment I don't know how to pass current directory|
;;; |    to SumatraPDF setting, so EMACS_ROOT has to be hard coded, e.g.,      |
;;; |    'C:\path\to\emacs' (local drive) or 'U:\path\to\emacs' (EWS network   |
;;; |     drive).                                                              |
;;; | 4. Also go to 'Settings -> Advanced Options' and set                     |
;;; |    'EnableTeXEnhancements = true'.                                       |
;;; +--------------------------------------------------------------------------+

;;; Always start the server for inverse search
(setq-default TeX-source-correlate-start-server t)
;;; ____
;;; Note: If error pops up when 'C-c C-c' view the pdf file,
;;; ¯¯¯¯
;;;     +---------------------------------------------------------------------+
;;;     | server-ensure-safe-dir: The directory '~/.emacs.d/server' is unsafe |
;;;     +---------------------------------------------------------------------+  
;;;
;;;       go to '~/.emacs.d/' and change the owner of folder 'server' to your
;;;       own account from 'Administrator'. This is most likely the case when
;;;       you unpack emacs in 'C:\' drive on lab computers. 'U:\' drive does
;;;       not suffer from this problem but things run slower.

;;; Turn on pdf mode
;;; See more about 'hooks' with 'lambda' function,
;;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Hooks.html
(add-hook 'LaTeX-mode-hook
          (lambda ()
            (tex-pdf-mode t)
            (TeX-source-correlate-mode t)
            (auto-fill-mode t)))

;;; Set SumatraPDF as PDF viewer. See known problems in 'Reeeeaaaaddddme.txt'
(setq TeX-view-program-list
      ;;'(("Sumatra PDF" ("\"~/../SumatraPDF312/SumatraPDF.exe\" -reuse-instance"
      '(("Sumatra PDF" ("SumatraPDF -reuse-instance"                  
                        (mode-io-correlate " -forward-search %b %n ") " %o"))))
;;; (Fixed) 'SumatraPDF' is in the path, no need to provide path for *.exe

(setq TeX-view-program-selection
      '(
        (output-pdf "Sumatra PDF")
        ))

;;; Helm mode
;;; ---------

;;; Helm mode is an enriched version of 'M-x'
(require 'helm-config)

;;; Org mode
;;; --------

;;; We can override default org with more recent org from orgmode.org
(add-to-list 'load-path "~/.emacs.d/elpa/org-9.1.13/lisp")         ; custom org path
(add-to-list 'load-path "~/.emacs.d/elpa/org-9.1.13/contrib/lisp") ; custom org contrib
(require 'org)
;;; Define global key for org agenda
(define-key global-map "\C-cl" 'org-store-link)
(define-key global-map "\C-ca" 'org-agenda)
;;; Define path for agenda
(setq org-agenda-files (list "~/../../Users/name/Nextcloud/Documents/notes/org/work.org"
                             "~/../../Users/name/Nextcloud/Documents/notes/org/school.org" 
                             "~/../../Users/name/Nextcloud/Documents/notes/org/home.org"))
;;; Turn on done tag for todo
(setq org-log-done t)         ; Append a time stamp to DONE task

;;; Turn on auto-fill-mode and flyspell-mode when opening *.org files
;;; flyspell-mode can be so slow that org-ac is useless so disable it
(add-to-list 'org-mode-hook
             (lambda()
               (auto-fill-mode t)))
               ;(flyspell-mode t)))
;;; Turn on auto-complete for org-mode
(require 'org-ac)
(org-ac/config-default)

;;; Matlab mode
;;; -----------

;;; For Windows, see https://www.emacswiki.org/emacs/MatlabMode#toc3 
;;; Need to put 'matlabshell.cmd' and 'matlabshell.exe' under emacs root
;;; org-mode syntax highlighting 
(setq matlab-shell-command "~/matlabshell.cmd")
(setq matlab-shell-command-switches '())
(setq matlab-shell-echoes nil)

;;; Network security !!! very important !!!
;;; ---------------------------------------

;(defun gnutls-available-p () nil)
(require 'tls)
;;; https://www.gnu.org/software/emacs/manual/html_node/emacs-gnutls/Help-For-Users.html
(setq gnutls-log-level 1) ; 0 - 99 will show details when logging into e.g. gmail 
(setq tls-program
      '(; "openssl s_client -connect %h:%p -no_ssl3 -no_ssl2 -ign_eof -CAfile %t"
        "gnutls-cli -p %p --dh-bits=2048 --ocsp --x509cafile=%t \
--priority='SECURE192:+SECURE128:-VERS-ALL:+VERS-TLS1.2:%%PROFILE_MEDIUM' %h"))
(setq tls-checktrust t)
(setq gnutls-verify-error t)
(setq network-security-level 'high)
(setq gnutls-min-prime-bits 2048)

;;; Gnus + Gmail
;;; ------------
(require 'nnir) ; for email search; in group buffer type 'GG'

;;; Gnus 
;;; ----

;;; Settings copied from https://www.emacswiki.org/emacs/GnusGmail
;;; personal info is stored in ~/.authinfo.gpg (automatic GnuPG encryption) 
(setq user-mail-address "han82@illinois.edu"
      user-full-name "Yün Han")

;;; Windows only 
(if (eq system-type 'windows-nt)
    (setq gnus-select-method
          '(nnimap "gmail"
                   (nnimap-address "imap.gmail.com") 
                   ;; it could also be imap.googlemail.com if that's your server.
                   (nnimap-server-port 993)    ; windows only
                   (nnimap-stream ssl)         ; encryption
                   (nnir-search-engine imap))) ; add this line for email search
)

(setq smtpmail-smtp-server "smtp.gmail.com"
      smtpmail-smtp-service 587
      gnus-ignored-newsgroups "^to\\.\\|^[0-9. ]+\\( \\|$\\)\\|^[\"]\"[#'()]")

;;; Turn on html email reading
(setq mm-text-html-renderer 'w3m) ; need cygwin then install w3m
;;; Add w3m to exec-path 
(setq exec-path (append '(
                          "~/../../cygwin64/bin" ";" ; installed c:\cygwin64
                          exec-path)))

;;; Avoid format-flowed in encoding but display the message with wrap in buffer
(setq fill-flowed-display-column nil)
(add-hook 'gnus-article-mode-hook
  (lambda ()
    (setq
      truncate-lines nil
      word-wrap t)))

;;; Outgoing email spell check with flyspell-mode
(add-hook 'message-mode-hook
          (lambda ()
            (flyspell-mode 1))) ; let's see if it works on windows machines

;; Unicode fonts for emails
(set-fontset-font t 'unicode "Symbola" nil 'prepend)

;;;; Use PragmataPro font (testing, not working as of now)
;;; Add the font from path 
(add-to-list 'bdf-directory-list "~/.fonts")
(setq bdf-directory-list
      '("~/.fonts"
        ))
;;(setq w32-bdf-filename-alist
;;      (w32-find-bdf-fonts bdf-directory-list))

(defvar is-windows-p (eq system-type 'windows-nt))
(defvar is-osx-p (eq system-type 'darwin))
(defvar is-linux-p (eq system-type 'gnu/linux))

(defvar default-font-name
  (cond (is-windows-p "PragmataPro-12") ; :weight=bold:slant=italic")
        (is-osx-p "PragmataPro-15")
        (is-linux-p "PragmataPro-11")
        (t "PragmataPro-11")))

(add-to-list 'default-frame-alist `(font . ,default-font-name))

;;; Turn on recentf-mode
(require 'recentf)
(recentf-mode 1)

emacs_launch.bat File

This file is used to launch emacs. It resides alongside .emacs in EMACS_ROOT.

@echo off
rem for echo to work inside if statement 
rem setlocal EnableDelayedExpansion

rem This is Windows *.bat file for launching portable emacs
rem by Yun Han@ECE 486 Lab
rem 2017-08-14
rem updated for emacs 26.1, GnuPG 2.2.7 and multi dict support
rem 2018-06-06
rem updated for GnuPG 2.2.8 
rem 2018-06-17

rem Set emacs HOME as current directory
set HOME=%~dp0
rem Set gnupg HOME as current directory
rem set GNUPGHOME=%~dp0
rem Add .\bin (emacs) and ..\SumatraPDF312 and ..\GnuPG228\bin to PATH
set PATH=%~dp0bin;%~dp0..\SumatraPDF312;%~dp0..\GnuPG228\bin;%PATH%
rem Add ..\miktex29\texmfs\install\miktex\bin to PATH
set PATH=%~dp0..\miktex29\texmfs\install\miktex\bin;%PATH%
rem Add cygwin64\bin to PATH
set PATH=%~dp0..\..\cygwin64\bin;%PATH%
rem Launch emacs. Note '%*' for situations where input args are present
"%~dp0bin\runemacs.exe" %*

Test Run

Now winematex is up, let’s give it a test run.

  • Is C-c C-c working for *.tex?

    The first C-c C-c will prompt us to LaTeX the *.tex file. The second C-c C-c will prompt us to View the *.pdf file. Press Enter to confirm and SumatraPDF viewer is supposed to pop up.

    Use C-c C-v to forward search and double click the text in the viewer to jump back to source, called inverse search.

  • Is M-x gnus working for gmail?

    The latest version is 5.13 and it is supposed to show a large Gnus Emacs logo in colour before take us to email group buffer.

  • Is C-c C-e h o working for *.org?

    It is supposed to export our planning doc *.org file to an HTML and open a web browser to render it.

  • Is M-x ispell-change-dictionary working for different languages?

    Words not in a Hunspell dictionary will either show up in a different colour or with a wavy underline.

Now What? It’s Working but I Want to Move to Unix/GNU Linux…

Great! Check out veteran Unix systems such as FreeBSD and Linux flavour Debian.

Note on Unix many binary files are available in $PATH and it is a good idea to split .emacs into multiple files and group them into different folders.

Author: Yün Han

Emacs 26.1.50 (Org mode 9.1.13)