Want to take part in these discussions? Sign in if you have an account, or apply for one below
Vanilla 1.1.10 is a product of Lussumo. More Information: Documentation, Community Support.
The big thing that I dislike about editing entries on the n-lab is having to send them to the server to see what they look like. (This is a basic problem with the client-server model and nothing whatsoever to do with Instiki, and also nothing to do with how it implements previews - or rather, how it doesn't implement previews.) One solution would be a sort-of AJAX set-up, but I don't know much about javascript and I'm trying to learn a bit of Ruby so learning JS would just be too confusing. A better solution, to my mind, is to have a local installation of the filter so that one can compile the document locally to see what it looks like before sending it to the server. (I should add that I can never get indentations right first time so often have to do a lot of minor tweaks to get lists to work correctly. Even using a local server (as I'm doing for a course I'm teaching), it gets annoying to have to reload it each time.)
Essentially, what I want is when I am writing an entry to be able to forget that I am using any off-site software and go through the usual edit-compile-check cycle that I would for, say, a LaTeX document.
Thanks to the wonderful "It's all text" plugin for firefox, I can edit n-lab entries in Emacs. That's the crucial step in getting the document off the off-site system and onto the local system. Next step is to install the filter. That's maruku and it's available as a ruby gem (for me, as I don't have sysadmin privileges on my work machine, that involved also installing ruby locally). Similarly, itex2MML is simple enough to install. Getting everything together took longer than it should, but isn't overly difficult once you know the steps.
I have a wrap-around for the standard tex-mode
that comes with Emacs (I'm using a slightly modified version of 22.0.50, by the way) which allows me to specify different output formats for LaTeX documents so it was simple enough to add maruku as one of them.
Font-locking for LaTeX doesn't look great on a Markdown document, but that's okay because we can load the font-lock defaults from the markdown-mode that Jason Blevins wrote (I've never used any of the commands that the markdown-mode defines, but there doesn't seem to be an overlap with the LaTeX set - but I don't make heavy use of the commands so I haven't extensively tested them).
The main thing is to get all of this done automatically when loading a file from an Instiki installation. This is where the plea for help comes in. I notice on the n-Lab HowTo that Mike has written some code to automatically load latex-mode when the document comes from golem or ncatlab. I need to add at least one more host to that list. It'd also be nice to add a few more commands to the hacks so that the maruku format was chosen by default and the font-locking as well. Unfortunately, my LISP is only slightly better than my Javascript and this looks a bit technical, so I'm hoping that some kindly person might be able to help me out here.
Concisely,
\end{environment}
(I think it's C-c C-e
). Can we adapt this to insert =--
s as well?Further details, including my emacs additions, can be found at my homepage (Note that I got the diff the wrong way around!).
So ... any Emacs gurus out there ... ?
And another thing, to get the preview to display nicely, it needs a stylesheet. Maruku can cope with this via meta-data. This is ignored by Instiki so it's okay if it gets put in by accident, but it would be best to have this as only local. Maybe wrap maruku in a filter that automatically appends the meta-data? How complicated am I prepared to make this! (Actually, such a wrapper would be dead easy, but if we're adding command line options to maruku, maybe specifying a style sheet would be reasonable.)
A quick answer to your first two questions:
(setq instiki-file-regexp-list
'("\\(www.\\)?ncatlab.org"
"golem.ph.utexas.edu"
"nlab.mathforge.org"))
(setq instiki-file-prefix "/itsalltext/")
(mapcar '(lambda (site)
(add-to-list 'auto-mode-alist `(,(concat instiki-file-prefix site) . latex-mode)))
instiki-file-regexp-list)
(defun instiki-latex-fixes ()
(when (some '(lambda (site) (string-match (concat instiki-file-prefix site) buffer-file-name))
instiki-file-regexp-list)
(longlines-mode t)
(set (make-local-variable 'TeX-open-quote) "\"")
(set (make-local-variable 'TeX-close-quote) "\"")
))
(add-hook 'LaTeX-mode-hook 'instiki-latex-fixes)
Now you can just add entries to "instiki-file-regexp-list", which should hopefully be clear how to do.
Probably the "right" thing to do is to define a new major mode, which inherits stuff from both latex-mode and markdown-mode (which I didn't even know existed). I'll think about this a bit.
Is there a reason you don't use auctex-mode? I like it much better than the default tex-mode.
That looks great! Thanks.
In answer to your question about auctex, I'm very much a command-line junkie. I don't like it when things try to get "too clever". Learning loads of shortcuts and macros is extremely irritating. I frequently use 'M-x commandname' and although Emacs snootily tells me that there's a shortcut to remember, I never do. Or almost never. I can just about remember 'C-x C-s C-c C-f' so if I can make it so that everything uses that key combination, I'm happy! That's one reason why I tend to use Emacs more than vim - in vim you have to remember so many key combinations before you can even begin. Emacs, you can take 'em or leave 'em.
I don't have the menu bar displayed in my emacs. In fact, I try to use the mouse as little as possible - better to stick with the keyboard than keep swapping back and forth (my window manager isn't ratpoison, but only because I didn't know about it and got used to sawfish). Slightly more seriously, I nearly got RSI a few years back so I'm quite careful about not stretching my hands out too much and avoiding having to hit control and alt and meta too much (I have a keyboard setting for typing latex documents in which, for example, the backslash is where the semi-colon usually goes).
So although I've often wondered about auctex, I've never felt unhappy enough with what I'm using to change. Of course, I've felt slightly unhappy with the standard tex mode which is why I have a wrapper script for it, but never quite enough to venture into the Deep Waters that is auctex.
The local preview, by the way, was extremely useful today. I was typing the questions for next week's homework for my class and it was much quicker doing them in emacs and looking at them locally than sending them off to the server each time, even though the server is reasonably local! And making the mode load correctly automatically will be the icing on the cake so thanks again for the hacks, I'll try them out next week.
The rest is just the candles, nice but not necessary. I'll probably try to figure them out, just because not doing so will annoy me.
It's been a while since I used the ordinary tex-mode, but I think that auctex actually has fewer key combinations for some things. For instance, the same command "C-c C-c" is used for running TeX and for viewing the output; it guesses which one you want based on whether the file has changed since you last ran TeX successfully, but it also prompts you to choose a different one if you want.
I try to use the mouse as little as possible - better to stick with the keyboard than keep swapping back and forth
Me too (I also have the menubar and toolbar disabled on emacs, partly because I never use it and also to conserve screen real estate). But this is one reason I love the thinkpad touchpoint so much -- when I do have to use the "mouse" I don't have to move my hands off the keyboard.
I have a keyboard setting for typing latex documents in which, for example, the backslash is where the semi-colon usually goes
My backslash is where the apostrophe usually goes (or would go if I didn't use a dvorak layout otherwise), with dollar sign on the same key with shift. But I'm not really satisfied with that because often when I want to type dollarsign-backslash I end up with them in the wrong order. So I'm curious, where is your dollarsign?
You use dollars?
Oh, I forgot, iTeX is backward in that regard. However, if you say that you use dollars in LaTeX then I'll never speak to you again! (Only kidding)
I don't use dollars at all so that wasn't a key issue in my keyboard switches. They happen to be in place of the 4, but that's a side-effect of switching the numbers with their shifted keycodes. I find that I use some of the shifted keycodes much more than the corresponding numbers (%,^,&,(,) probably top of the list) so it made sense to swap them all rather than just a few. My main finger savers were the aforementioned backslash instead of the semi-colon, and swapping the square and curly brackets over.
Where it gets really confusing is that I sometimes have to type Norwegian characters so have another keyboard combination that puts the three extra Norwegian characters somewhere useful. I've yet to figure out a good system for when I'm typing Norwegian LaTeX documents, though.
Looking at my .xmodmaprc
then the logic seems to have been that I put the backslash somewhere sensible, swapped the brackets, and swapped the numbers. The rest is then a bit of shuffling to make sure that everything is somewhere. Oh, and I seem to have swapped the tilde and grave accents. I did this about 5 years ago so the logic is a little lost in the mists, as with any system once you've worked with it and gotten used to it then there needs to be something very wrong with it before you'll make a change. That's why I stick with qwerty - I've learnt it and I'd rather not have to remember that the keyboard in front of me is different when I'm on someone else's computer.
One other thing I remember doing is a character count of my LaTeX documents to see which characters I used most. Quite a useful thing to do when planning a layout. The numbers were way down the list so I saw no reason to have them in such an accessible position.
And of course I ditched caps lock a long, long time ago.
I've heard that one should use \[...\] instead of double-dollar-signs in LaTeX, for some reason that I forget, but no one has ever told me that I shouldn't use single dollar-signs for inline math. My copy of the LaTeX book says something like "inline math can be introduced by either of the short forms $...$ or \(...\)". What's the problem with $...$ and where should I have learned about it, if not in the LaTeX book? I generally like $ better than \( because it's one fewer key press. Plus if I got in the habit of using \( in LaTeX then I would probably unthinkingly try to use it in iTeX too and that wouldn't work.
I'm also a little amused to hear you say that (1) you've completely rearranged the placement of symbols and numbers on your keyboard, but (2) you'd rather not have to remember that the keyboard in front of you is different when you're on someone else's computer. I presume that in (2) you're referring only to the letter keys and don't mind having the symbols in different places?
One reason to use \(
…\)
and \[
…\]
instead of $
…$
and <latex>
…</latex>
is that then you can define them to be some clever macro instead of just something of catcode
4. Standard LaTeX does this with \[
…\]
, so people learn to use that, but not with \(
…\)
, so people don't learn to use that. But what if you do think of something fancy to do with inline math? If you always use \(
…\)
, then you'll be set!
I use:
\def \errmathmode {\ifmmode
\errmessage {You did not properly exit math mode
before using this command}$\relax \fi }%$
\def \(#1\){\errmathmode \leavevmode \ic $#1$}%
\def \){\errmessage {Bad math delimiters!}\ifmmode $\fi }%$
(where \errmathmode
is used before several other macros and \ic
is my fancy version of \/
).
I think that there's also an argument that sometimes dollar signs get unbalanced, so it helps when debugging if the beginning and ending codes are different. (Of course, that's what \errmathmode
is all about.)
(Ha, look what happened to my double dollar signs! It was perfect on preview, of course.)
Emacs' font-locking always tells me if my dollar-signs get unbalanced; I've never had a problem with that. And it seems to me that most commands that don't want to be in math mode will already complain if they're used in it; I don't think I've ever had a problem with that either.
Also, couldn't one redefine $ to be an active character if one wanted it to do fancy things?
Finally, if I ever did think of some reason to use \( instead of $, I could just do a search-and-replace on any existing file, so I'm not convinced by "use \( in case you ever want to do something fancy with it"
Also, couldn't one redefine
$
to be an active character if one wanted it to do fancy things?
Yes, although the coding is a slightly harder that way.
Emacs' font-locking always tells me if my dollar-signs get unbalanced
Yeah, one upside to using \(
with Emacs in TeX mode is that then it doesn't do the annoying math-font that overrides all of the other clues from font-locking. If I type $ \alpha beta $
, then I can't tell if anything's wrong, but if I type \( \alpha beta \)
, then I can.
Of course, I could remove that feature from TeX mode. I agree that there is a reply to every argument for one over the other, and in the end it comes down to preference.
Auctex-mode font-locks \(...\) in math mode just the same as $...$ (by default, that is). And I like having math mode in a different color, because I can tell where my math mode blocks begin and end. (Although your comment suggests to me that maybe math-mode font-lock should ideally be a background color, so that foreground colors could still convey different information.) But this conversation is rapidly degenerating past the point where I expect anyone else would be interested in it—although I'm still curious why Andrew would refuse to speak to me for using dollarsigns if, as you say and I agree, it comes down to preference in the end. But if he's actually refusing to speak to me, then maybe I'll never find out. (-:
This is wandering slightly off-topic, but it's quite fun too so why not?
These are the reasons to use parentheses (rounded and square) over dollars:
Neither is equivalent. If you look at the latex code (latex.ltx
) then you'll see that the rounded parentheses already have Toby's error checking builtin:
\def\({\relax\ifmmode\@badmath\else$\fi}
\def\){\relax\ifmmode\ifinner$\else\@badmath\fi\else \@badmath\fi}
whilst the square brackets have error checking and a little alteration to the spacing before the mathematics mode starts (you have to encounter just the right combination of modes for this to kick in, you have to be already in vertical mode when you start the mathematics.)
LaTeX is a layer on top of TeX. Thus whenever you use a TeX primitive you should do so in the full knowledge of what you are doing. That's why we have \newcommand
instead of \def
and similar things. It's like using XHTML directly in an iTeX document. It's not wrong, but unless you really need to use it then it's bad style.
When I originally realised that there was a difference, Emacs worked so much better with parentheses than dollars. It may be different now, of course. It wasn't just the font-locking, but also the fact that when I close a parenthesis, Emacs will flick back to the opening parenthesis and show me where it began. That's an extremely useful feature that I'd like not to break. Indeed, if I have unbalanced parentheses for some reason (say, for open-closed intervals), I'll often comment in a balancing parenthesis just so that Emacs doesn't get confused!
It's a real pain to program against dollars. I've written a perl script that can do search-and-replace inside mathematics, so that when you decide that your generalised cohomology theory should be denoted by F
instead of E
then it's easy to change (of course, that was before I figured out how to do object-oriented macros in TeX). Imagine doing that with a general search-and-replace rather than a mathematics-specific one. Matching parentheses was realitively simple. Matching dollars was something I decided not to tackle (and if you think it's easy, imagine two inline mathematics back-to-back. That produces a double dollar which is not a double dollar). As I have been known to collaborate, I also have a script that converts all dollars to parentheses (so I do know how to program it, I just did it once and then decided it was so awful I didn't want to do it again) so if anyone is now convinced of the Error of their Ways, I can help them Return to the True Path.
So while it is, in the end, preference. It's the same preference that leads one to write \hspace{2em}
instead of \hspace{20pt}
, or instead of ~~~~
.
PS I had to think carefully how to phrase a few things here to avoid them getting converted into mathematics! I managed to hack iTeX into producing a PHP version last week. I was all ready to install it here when I discovered that you need sysadmin privileges to do it because of the way it works (as a wrapper round a C-module). But that's a story for another discussion.
And in reply to Mike's amusement over my keyboard rearrangements, you are absolutely correct. In fact, to avoid some of the problems I have rigged my computers up so that when I lock the screen then first they reset the keyboard to its "natural" state so that I don't have to remember whether I left it in TeX mode or normal mode before typing in my password to unlock it. The only time I get into trouble is on my rickety old ibook (running Linux) which does an automatic screen-lock which doesn't reset the keyboard. But that's only because I've not fully configured it yet (that machine is a bit like Samuel Johnson's dog: it's amazing that it's even running anything, minor things like remembering the keyboard are nothing).
On the other hand, the keyboards here are Norwegian which is not in my "muscle memory" (grr, spell-checker's not working so although 'muscle' looks wrong, I can't figure it out without more work than I'm prepared to do). So I use a US/UK keyboard layout as my base-line. That can cause confusion when I am logged in on a console rather than an X session, but that happens so rarely that I can live with it (it does tend to confuse my wife who does look at the keyboard to see what she's typing, though).
Responses:
Error-checking only seems necessary if your left and right math-mode delimiters are different. If you're already in math-mode and you type \(, then sure that's a problem, but if you type $, then that's no problem at all, it just ends math mode; there's never any possibility of "nested" math-modes. So if you say "use \( for error-checking" I respond that if I use $, then I don't need error-checking.
Thanks to you, I do now have full knowledge of what I am doing. \( is the same as $ except that it has error-checking, which I don't need.
Emacs (at least, auctex) will now flick back for dollars as well.
Why is converting dollars to parentheses hard? If you assume that dollars always come in matched pairs, then shouldn't s/\$(.+)\$/\\(\1\\)/g
do it? Unless people are also using $$s instead of \[, but I've already agreed you're not supposed to do that, because it actually does something visually different.
Also, I would rarely feel comfortable doing a global search-and-replace even inside of mathematics. For instance, if I change my generalized cohomology theory to be F instead of E, as you suggest, then the category SET would become SFT. I always use Emacs' interactive search-and-replace. I've never really felt the need for one that operates only inside math-mode, but I can imagine that I might, and I might then be inspired to write one. But such a thing could actually also piggyback on auctex's font-locking to detect where math mode begins and ends, so it wouldn't have to implement that itself.
Also, you didn't answer my question of "where should I have learned about it, if not in the LaTeX book?" My copy of the LaTeX book explicitly says that you can start math-mode with dollarsigns, although it doesn't mention anything about using double dollarsigns for displays.
I don't understand this at all. If you try to enter math mode while you're already in math mode, then that's an error, whatever symbol you use. With dollar signs, you might not catch it for some time and get
Let and da + b = c + df: Z \to …
… wait, what do you mean 'Missing $ insterted.'? There's no missing $ there!
Well, my \(
also fixes the spacing in ‘Note that is also the square of .’ (no italic correction after ‘of’, so it bumps up against the absolute value bar), but LaTeX's doesn't.
(This entry deliberately left blank.)
Don't forget to check for \$
first.
I also always put spaces around every math element so that E
won't blend into SET
.
That's what font-locking is for. Programmers have been using " to denote both the beginning and the end of a string for years and I've never heard anyone complain that they need different symbols.
I must admit to not really ever worrying about italic corrections.
...
I don't think I've ever written a math paper that discussed money or anything else requiring a \$, and I have a hard time imagining that I might. I've started trying to get in the habit of spacing things more now that I have to do it for itex, but I still forget occasionally. I still prefer the interactive version.
I am starting to see that there are a few reasons for using \(, but I don't think they are compelling enough for me yet to try to change my habits. Possibly if itex starts to accept \( then I'd think about using it.
OK, so your response is not ‘if I use $
, then I don't need error-checking’ but rather ‘if I use font-locking, then I don't need error-checking’.
Presumably that's because you've never been annoyed by an italic ‘f’ next to a straight math symbol on a justified line where spacing is tight. (^_^)
I am starting to see that there are a few reasons for using
\(
, but I don't think they are compelling enough for me yet to try to change my habits.
I'm not going to try to convince you of anything stronger than that. I started using \(
when I wrote that italic-correction code (the error-checking came later), and it was a slight pain to switch (but worth it to me in the example that I gave); that's all.
You've left me point 3. Let me just check if Emacs' behaviour is what it used to be ... hmm, not clear. My emacs doesn't do the flick-back for dollars, but that may be because I've told it not to. I don't seem to have done so, but then I don't have auctex installed and I'm not going to install it just for the sake of checking this example. However, does the flick-back know the difference between start and end of mathematics? Namely, when you put in the opening tag, does Emacs flick back to the previous closing tag?
Also, I would rarely feel comfortable doing a global search-and-replace even inside of mathematics ... I've never really felt the need for one that operates only inside math-mode, but I can imagine that I might, and I might then be inspired to write one.
Well, if you do then you don't have to because I've already done it. Of course, it has a test mode so that you can see if it does what you want, and saves a backup of the original. It can also operate purely as a search without doing a replace, which can be useful for finding out if you've used a particular string in the mathematical section.
I am starting to see that there are a few reasons for using (, but I don't think they are compelling enough for me yet to try to change my habits. Possibly if itex starts to accept ( then I'd think about using it.
I don't think that either of us are trying to convince you. If we ever collaborate on a paper, then that'll be a different matter and you'll have to change your habits.
However, does the flick-back know the difference between start and end of mathematics? Namely, when you put in the opening tag, does Emacs flick back to the previous closing tag?
Yes, and no, respectively.
It doesn't handle double-dollars quite right, though (which I never notice because I don't use them): the second $ causes it to flick back one character to the first, and the ending double-dollar causes no flickbacks at all.
Actually, auctex doesn't flick back for \(...\), or for \[...] for that matter, which I also never really noticed for some reason. It also doesn't treat them as matching, e.g. when my cursor is after the closing \) it is highlighted in purple as a "not matching paren" rather than highlighting the \( as matching it. Probably this is due to someone thinking that backslashes should remove all special meaning of the characters they follow, which is true in many cases (e.g. \$) but not these. But I'm surprised no one has fixed that by now.
if you do then you don't have to because I've already done it.
Sorry, what I wrote wasn't clear. You'd already indicated that you'd written such a script (and it looks very cool, by the way; I'll remember its existence in case I ever want it), so I meant to refer to an interactive math-mode search-and-replace, like Emacs' "query-replace" command.
On the subject of Emacs (sort of) and math-mode, has anyone ever modified "ispell" to ignore math-mode? It's smart enough to ignore backslash-commands and \labels, but $fg=h$ makes it think "fg" is a spelling mistake. And yes, I could and probably should write that as $f g = h$, but \ar[dr] in xypic isn't so easy to fix.
1 to 20 of 20