Tuesday, July 14, 2015

Emacs cc-mode indenting

Use cc-mode to set emacs coding styles for different languages. The configuration basics shows how to use hooks in the .emacs file. I wanted to  customize indentation and you can interactively determine which parameters to change and test different values.
   The default GNU style indents C++ as shown below.
for (unsigned i = 0; i<10; i++)
  {
    std::cout << i << std::endl;
  }
I want to indent this way
for (unsigned i = 0; i<10; i++)
{
  std::cout << i << std::endl;
}
So I added the my-c++-mode-hook at the bottom of my /home/USER/.emacs file.  I've copied the entire file to have a record of my current settings.

;;;Use font lock mode
(global-font-lock-mode 1)

;;;keep the display simple
(scroll-bar-mode 0)
(menu-bar-mode 0)
(tool-bar-mode 0)

;;;Pretty colors
(set-background-color "darkslategrey")
(set-foreground-color "lightsteelblue")
(custom-set-variables
  ;; custom-set-variables was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
  '(inhibit-startup-screen t))

(custom-set-faces
;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)

;; change the substatement indenting to 0 so opening bracket on next line is below first letter of conditional statement
(defun my-c++-mode-hook()
  (c-set-offset 'substatement-open 0))
(add-hook 'c++-mode-hook 'my-c++-mode-hook)

Wednesday, January 14, 2015

Construct a triangle given angle a, altitude of a, and the perimeter

I read How To Solve It by George Polya and went overboard solving one of the example problems: Construct a triangle given the vertex angle, the height of the vertex, and the perimeter.  Here is my solution in PDF. Please leave comments to correct any mistakes.  Here are the source files as tarball.

I created the figures with eukleides, a language devoted to plane geometry.  There is not a lot of documentation but hopefully my figure source files (in the above tar ball) can help you get the gist of it.  Eukleides produces very nice figures.  Create an EPS from the EUK file, then convert that with epstopdf to include it in the latex file.
$> eukleides FIGURE.euk
$> eps2topdf FIGURE.eps
I created the document in LaTeX, specifically the pdflatex package.