For the English part of the blog, see Content AND Presentation.

2019-05-20 Converting BibTeX files to AMSrefs

It’s been a long time since I’ve written anything TeX-related here. But I’m still working with LaTeX (though less often than I used to), and here is a problem I encountered a few days ago – and a solution.

I received a file with BibTeX-encoded bibliography. Obviously, I wanted to convert it to AMSrefs. Being lazy, I started to search for an automated solution – and I was not disappointed at all! It turns out that AMSrefs itself has a feature I needed.

Assume the following structure. The file example.tex looks like this:


Lorem ipsum.  See \cite{fasc-paper}.



The file example.bib looks like this:

  Author = {Thor, A. U.},
  Journal = {Some journal},
  Pages = {111-222},
  Title = {A fascinating paper},
  Volume = {1},
  Year = {2009},

After the usual compile-bibtex-compile-view cycle, we get the example.bbl file and a nicely produced pdf.

However, what we can do is to change the abbrv to amsrn, and voilà! our example.bbl file now looks like this:

% \bib, bibdiv, biblist are defined by the amsrefs package.

      author={Thor, A.~U.},
       title={A fascinating paper},
     journal={Some journal},
       pages={111\ndash 222},


In order to properly compile example.tex we only need to add \usepackage{amsrefs} and we’re done! (Of course, there is now no need to use the bbl file – I prefer to copy-paste it to the main one.)

If you want to learn more (in particular, how to use other styles when converting to AMSrefs), look for the amsxport.pdf file in your TeX distribution. The easiest way to find it is by saying texdoc amsxport in your terminal.

CategoryEnglish, CategoryBlog, CategoryTeX

Comments on this page

2019-05-11 Toggling modeline clock display

As I mentioned a lot of times, I use Org-mode clocking all the time. Among others, I integrated it with two external services, I have a few dedicated keybindings to it in my Org-mode hydra. It’s no wonder that I work hard to make clocking as smooth as possible.

I used to have the variable org-clock-mode-line-total set to 'today. This means that the clock info in my modeline reflects the time I spent on this particular task, well, today. (This fits nicely in my Beeminder workflow, where I set daily goals for various stuff, measured in minutes).

However, I’m also working on my productivity, and I was toying with the idea of using the famous pomodoro technique. The main idea is that you work in 25-minute intervals with 5-minute breaks.

While I do not like the rigidity of that scheme, the idea appeals to me. There are a few Emacs-based solutions (and even one or two Org-mode ones), but none of them really resonates with me. I will definitely look into integrating some kind of timeboxing technique into my workflow in the future, but for now, I settled for a minimalist solution.

The idea is that both 'today and 'current are reasonable values of org-clock-mode-line-total for me, and hence I’d like to be able to switch between them seamlessly. This way, I could either easily see how much time I spent on the currently clocked task in this particular “timebox”, or how much I spent on it today. (Having that, I decided that seeing how much I spent on it altogether can also be useful.) Since I already have my Org-mode related hydra, I decided to add one more command to it: toggle-org-clock-mode-line-total-setting. The idea is to be able to cycle between various settings of org-clock-mode-line-total with a keystroke.

So, I started with this:

(setq org-clock-mode-line-total-settings
      '((current . "time spent in this chunk on the current task")
	(today . "time spent today on the current task")
	(all . "total time spent on the current task")))
(setq org-clock-mode-line-total-setting-number 0)

This is a very rudimentary implementation of a “ring”. A ring is just like a list, only when we want to go past the last element, we get at the first again. Actually, Emacs provides a “ring” package which implements such a data structure efficiently, but I decided that it would be an overkill for just three elements – here, the simplicity of the code won over the efficiency. (In fact, after looking into the “ring” package, I’m no longer sure whether my code is really that simple… I had to do the modulo wrapping by hand, for instance – Emacs’ “ring” does that for me.)

Now, let us implement the actual cycling. This proved (quite unexpectedly) to be the hard part, since just toggling org-clock-mode-line-total did not do the trick – somehow, I had to make Emacs recount the time of the current clocking item elapsed from the first clocking entry or just for today or the current entry.

(defun toggle-org-clock-mode-line-total-setting (setting-number)
  "Toggle between org-clock-mode-line-total settings.
With a numeric argument, use setting SETTING-NUMBER."
  (interactive "P")
  (if (numberp setting-number)
      (setq org-clock-mode-line-total-setting-number
	    (mod setting-number (length org-clock-mode-line-total-settings)))
    (setq org-clock-mode-line-total-setting-number
	  (mod (1+ org-clock-mode-line-total-setting-number)
	       (length org-clock-mode-line-total-settings))))
  (let ((org-clock-mode-line-total-setting (nth org-clock-mode-line-total-setting-number
    (setq org-clock-mode-line-total (car org-clock-mode-line-total-setting))
    (when (org-clocking-p)
      (setq org-clock-total-time
	    (with-current-buffer (marker-buffer org-clock-hd-marker)
	      (save-excursion (goto-char org-clock-hd-marker)
    (message "Modeline shows %s."
	     (cdr org-clock-mode-line-total-setting))))

The tricky thing is the latter part of the above code. Just changing the value of org-clock-mode-line-total in the middle of clocking does not have any effect – even if we actually call org-clock-update-mode-line. What we need to do is to call org-clock-get-sum-start, which (as Nick Dokos pointed to me) is the only place in the Org-mode sources where our variable is used. Mimicking its use in org-clock-in, I set the global variable org-clock-total-time and only then call org-clock-update-mode-line. This function calls org-clock-get-clock-string, which calls org-clock-get-clocked-time, which uses org-clock-total-time and adds the currently clocked time to its value.

Elementary, my dear Watson.

The moral of this story is that while Org-mode source code is sometimes a big mess, you can still do nice things if you are patient enough and can use grep (or ask wise people than can use it;-)).

CategoryEnglish, CategoryBlog, CategoryEmacs, CategoryOrgMode

Comments on this page

2019-05-05 A few Magit tips

A month ago I wrote about merging in Git without actually comitting the changes, and mentioned that you probably can’t do that from within Magit. It turned out that I was wrong – in fact, Magit can do it.

More recently, I wrote about another Git tip, which is staging an empty file. Then, Nicolas Petton asked whether it’s possible in Magit, and lo and behold – it is, in a quite intuitive (and documented in the docstring) way I just didn’t think about.

And much earlier I wrote about displaying more detailed information about your Git stashes, which prompted an anonymous comment about doing the same in Magit. Since then, I also learned how to make this the default – now I have this:

(setq magit-status-margin
  '(t "%Y-%m-%d %H:%M " magit-log-margin-width t 18))

in my init.el.

Well, the takeaway is probably that Magit really delivers on its promise to be “a Git porcelain inside Emacs”. The only thing I really miss in Magit is a simple way to use it (and Emacs) as a standalone Git frontend, for these poor people accustomed to toy text-editors instead of the real thing. ;-)

CategoryEnglish, CategoryBlog, CategoryEmacs, CategoryGit

Comments on this page