Home About me Blog Po polsku

Content AND Presentation

2014-08-18 find-function-view-mode

Tired of doing C-h f, then typing the function name and then C-x C-o TAB RET to go to the source, I finally put the find-function onto C-h C-f (replacing mostly useless Emacs FAQ) (I learned about find-function from the indispensable Emacs Redux post.) However, I usually don’t want to edit my Emacs’ guts in place, so I looked up the (two-line) source for find-function (guess how, ha, ha), and came up with this one:

(defun find-function-view-mode (fun)
  (interactive (find-function-read))
  (find-function-do-it fun nil 'switch-to-buffer)
  (view-mode 1))

(global-set-key (kbd "C-h C-f") 'find-function-view-mode)

Trivial, but very useful.

As a side note: I also added (global-set-key (kbd "C-z C-v") 'view-mode) to my C-z keymap. Being used to less (how metaphysical!), I like view-mode a lot. Give it a try if you happen to open files in Emacs just to look at them, not edit them.

CategoryEnglish, CategoryBlog, CategoryEmacs

Komentarze na tej stronie

2014-08-16 Catastrophic, lamentable idiosyncrasy

Some time ago, I submitted a paper to a mathematical journal. I downloaded the Instruction4authors.pdf, a template and the LaTeX class file. Then, I started to look at them. Then, I weeped.

Here’s an excerpt from the template (compiled from three places there):

\textheight=8.2 true in
\textwidth=5.0 true in
\topmargin 30pt
\setcounter{page}{1}

% Place all authors' names in [ ] shown as running head;
% No more than 40 letters. Leave { } empty
% Please use `and' to connect the last two names if applicable
\author[first-name1 last-name1 and first-name2 last-name2]{}

\begin{document}
\maketitle

% Enter the first author's name and address:
\centerline{\scshape First-name1 last-name1 }
\medskip
{\footnotesize
% please put the address of the first author
 \centerline{First line of the address of the first author}
   \centerline{Other lines}
   \centerline{ Springfield, MO 65801-2604, USA}
} % Do not forget to end the {\footnotesize by the sign }

\medskip

\centerline{\scshape First-name2 last-name2 and First-name3
last-name3}
\medskip
{\footnotesize
 % please put the address of the second  and third author
 \centerline{ First line of the address of the second author}
   \centerline{Other lines}
   \centerline{Springfield, MO 65810, USA}
}

\bigskip

% The name of the associate editor will be entered by an editorial staff
% "Communicated by the associate editor name" is not needed for special issue.
 \centerline{(Communicated by the associate editor name)}

(Not to mention that true declarations are not needed, since there is no \magsteps nor similar things anywhere.)

Now even funnier is that the cls file contains a \ProvidesClass declaration inconsistent with its own filename, and large, l@w@lev@l;) portions copy-pasted from amsart.cls (probably via that declared file, but that I am not sure).

Among other things, the cls file contains quite a few hyphenation exceptions. They include the words: “catastrophic”, “lamentable” and “idiosyncrasy”.

How appropriate.

CategoryEnglish, CategoryBlog, CategoryLaTeX

Komentarze na tej stronie

2014-08-08 A problem with a command with an optional star

TL;DR: I wanted to be smart, and it backfired.

I’m currently writing a (longish) document on mathematics. Among other things, I write about the Hausdorff metric, which I denote by d_H. Since this notation appears quite often, I decided to write a command for it:

\newcommand{\dH}{{d_H}}

Now what are the extra braces for? Sometimes I want to talk about a ball with respect to the Hausdorff metric, denoted by B_{d_H} – for that, I wanted to write B_\dH. Without the extra braces this won’t work (for obvious reasons).

So far, so good. But there’s another catch: I want a similar notion to the Hausdorff metric, which I denote d_H^*. With my definition, \dH^* won’t work (can you see why?). So I wanted to be clever, and use an optional star; this way, I could write \dH or \dH*. I did this:

\newcommand{\dH}{\@ifstar{d_H^*}{d_H}}

(The \@ifstar{whatever}{something else} macro (which must come as the last thing in your defined command!!!) “peeks ahead”, and if it sees a star (possibly after some spaces), it executes whatever, and something else otherwise.) But my ability to write B_\dH is lost now! And of course, adding braces around \@ifstar won’t help: it will then never “see” the star.

(Please note that if you want to define commands accepting optional stars and/or optional parameters, the xparse package is a better way to go – the \@ifstar macro is a low-level, LaTeX2e concept.)

It seems that there’s no way out of this dilemma. It’s not a big deal, I can write B_{\dH} (which is cleaner LaTeX syntax anyway), but I’m curious whether there’s any way to eat this cake and have it, too.

Edit: yes, there is a way, as this übercool answer from Enrico Gregorio shows. As pointed out in the comments, it’s better to stick to B_{\dH} syntax, though.

CategoryBlog, CategoryEnglish, CategoryTeX, CategoryLaTeX

Komentarze na tej stronie

Więcej...

(Więcej means More in Polish; click it to see older entries.)

CategoryEnglish, CategoryBlog