cdominik / cdlatex Goto Github PK
View Code? Open in Web Editor NEWFast input methods to enter LaTeX environments and math with GNU Emacs
Fast input methods to enter LaTeX environments and math with GNU Emacs
Hello, for some reason, cdlatex stopped functioning properly today. When I try to insert a math modifier under align, align*, equation* or multline environments, cdlatex throws the "No such modifier /modifier-symbol/ outside math mode." error. Furthermore, when I try to insert a math symbol under these environments the symbol is generated between double dollar signs as if it is called in the text-mode.
However, it works flawlessly and as it used to with the "equation" environment.
I am using AucTeX in Emacs 26.3 which was downloaded from emacsformacosx.com and my OS is macOS Catalina 10.15.5.
Hey all. I've been doing a bunch of multi-line equations. Adding a \\
at the end of each line is onerous and something I often forget. It would be wonderful if I could get a keyboard shortcut which would do something akin to "add a \\
to the end of this line and start a new line".
When using company it sometimes interferes with cdlatex, to circumvent this a simple fix is to create a company backend for cdlatex, like
(require 'cl-lib)
(require 'company)
(setq cdlatex-command-alist-comb-keys
(cl-map 'list #'car cdlatex-command-alist-comb))
(defun company-cdlatex-backend (command &optional arg &rest ignored)
"Company backend for cdlatex-command-alist"
(interactive (list 'interactive))
(cl-case command
(interactive (company-begin-backend 'company-cdlatex-backend))
(prefix (and (or (org-inside-LaTeX-fragment-p)
(eq 'major-mode 'latex-mode))
(company-grab-symbol)))
(candidates (cl-remove-if-not
(lambda (c) (string-prefix-p arg c))
cdlatex-command-alist-comb-keys))
(annotation (concat
(unless company-tooltip-align-annotations " -> ")
(nth 1 (assoc arg cdlatex-command-alist-comb))))
(doc-buffer (asoc arg cdlatex-command-alist-comb))
(post-completion
(cdlatex-tab))))
If you are interested in adding this function to cdlatex I am happy to create a PR.
I want cdlatex pass through $ when I type $ at the position before $.
ex)
type $
then Emacs print $$.
after I type some formula
$ blah blah (my cursor)$
Now I want to go out the dollar braces with typing $.
However right now, It will add another single $.
expected behavior : $ blah blah $(my cursor)
current behavior : $ blah blah (dollar sign)(my cursor)(dollar sign)
current behavior : $ blah blah
I don't know that it is intended. Since the 'expected behavior' happens with {}.
At least there should be an option for choosing this.
I am using spacemacs + smartparen mode by the way.
I'm using cdlatex with auctex. It seems that $$
in verbatim is also considered as math fragment, and that texmathp
has considered this case. Is there any features to disable this behaviour?
Thanks.
when typing e.g. "don't" in text mode, I get the error
cdlatex-math-modify: No such modifier ‘t’ outside math mode
I have a similar problem with "I'm". These modifiers work fine in math mode, and typing e.g. "it's" is fine too.
If I show the list of available modifiers by '?, t and m are both there, with blanks next to them.
The documentation says:
Also, if the key character is not associated with
an accent or font, the quote will be inserted. For example, "'t"
and "'s" insert just that, so that normal text typing will not be
disturbed.
Have I misunderstood the expected behaviour?
When I activate cdlatex-mode on a LaTeX layer document smartparens stops working. When I input (
I don't get a matching )
. The error I get is
Search failed: there is an unmatched expression somewhere or we are at the beginning/end of file.
When I use cdlatex in org-mode, everything works fine.
Hi here,
I'm using auctex + cdlatex, and I want to convert bla
to $bla$
automatically when be highlighted
and typeset a $
.
Currently, my observed result is bla$$
, which is not consistent with the LaTeX math environment.
See https://lists.gnu.org/archive/html/auctex/2023-05/msg00099.html for the related discussion.
Regards,
Zhao
My configuration of cdlatex with org-mode does not work well.
I think that the problem is related to having $
as the inline math environment.
To use the $
sign I have this in my config file
(after! cdlatex
(setq cdlatex-use-dollar-to-ensure-math t)
(map! :map (cdlatex-mode-map org-cdlatex-mode-map)
:i "TAB" #'cdlatex-tab))
My issues appear inside math inline environment $--$
.
$
chars, i.e. $|$
, then the snippet cannot be expanded. But, if I put in a whitespace (or any other character): $ |$
, it does get expanded.I understand that cdlatex does not deal with parenthesis.
However, I think that the issue is that I am not configuring properly the inline math environment to be used with dollar signs. How should I do that?
Note that in latex-mode everything works great, and that I run on doom emacs.
Hi,
I am using cdlatex in org-mode, and I need add more math symbols, so I modify cdlatex-math-symbol-alist
, but it seems I have to restart emacs to make it work.
In my case, I may need add many math symbols during my writing, restart emacs each time when I add one is a bit in-efficient, so is it possible to make it take effect after evaluate the setq
form?
Hi,
with the release of Emacs 28.1 the NonGNU ELPA repository has been enabled by default. As cdlatex is mentioned in the Org manual, it would be nice if it could be installed directly too.
From what I see everything should be fine, and the package could be added directly, if you have no issues with the procedure.
At the moment, cdlatex-mode shadows C-c ? with its own 'cdlatex-command-help.
I can understand doing that, but may I ask that the option of calling the original help function (which I find very useful) be preserved as a call to C-c ? with a prefix argument? C-u C-c ? , or, perhaps, C-1 C-c ?
Currently I cannot find a way to config several points of interest in environment template, and there is no hint about how to do that in README.
I tried to write a function, which uses the cdlatex-math-modify-function, to specialize it, such that, when the function gets called, the same happens as would happen, if I just press ' :
. The code of my function is this:
(defun xx-ddot (arg)
(interactive "P")
(progn (push ?: unread-command-events) (cdlatex-math-modify(arg)))
)
The problem is that when calling the function nothing happens, and I get the error-message "Symbols function definition is void: arg"
It seems like my usage of "arg" is incorrect, but leaving it out is also wrong, since cdlatex-math-modify needs an argument.
Do you know, how to fix it? (Or how to achieve the same goal with another method?)
There are a few scenarios in which left right parenthesis are not expanded properly in org mode.
Typing an inline math mode with $
, expanding lr(
does not work. Typing lr(
automatically closes the parenthesis, i.e. I get lr(|)
, and then hitting tab
puts the cursor out of the parenthesis, i.e. lr()|
. However when doing the same with lr[
, it also closes the parenthesis automatically to lr[]
, but the hitting tab
expand it properly to $\left[ | \right]$
.
When typing a yas-snippet, with multiple insertion place, like \frac{}{}
, I get that cdlatex is not expanded properly when the cursor is in the first spot, i.e. when \frac{|}{}
. However, this happens only for lr<
and lr{
. These lr(
and lr[
are expanded properly when hitting tab
.
I mean, when it does not work I get after expanding the snippet, and typing lr<
and tab
$\frac{lr<}{|}$
and when doing this with lr(
I get
$\frac{\left( | \right)}{}$
It seems to me like the problem might be related in the special role of <
and {
, in this function
(defun cdlatex-lr-pair ()
"Insert a \\left-\\right pair of parens."
(interactive)
(let* ((paren (char-to-string (preceding-char)))
(close (cdr (assoc paren cdlatex-parens-pairs)))
(paren1 paren)
(close1 close))
(if (string= paren "<") (setq paren1 "\\langle" close1 "\\rangle"))
(if (string= paren "{") (setq paren1 "\\{" close1 "\\}"))
(backward-delete-char 1)
(if (and (stringp cdlatex-paired-parens)
(string-match (regexp-quote paren) cdlatex-paired-parens)
(string= close (char-to-string (following-char))))
; parens are inserted paired, and there is already a closing parenthesis
(delete-char 1))
(insert "\\left" paren1 " ? \\right" close1)
(cdlatex-position-cursor)))
However, I do not know how to solve it.
In case anyone does, it would be nice.
Of course, this does not explain the 1st issue with the inline math.
Is there any way to have cdlatex-mode insert the unicode character instead of the tex code? I know about TeX input method, but the point of using cdlatex for me is much quicker insertion of characters.
Currently, the environment templates, e.g. equ
then tab
, insert the environment on the current line, if the cursor is at the beginning of the line; and first create a new line and then insert the environment if the cursor is at a line, where things have been typed before, i.e. the cursor is not at the beginning of the line.
This behavior is mostly great, because the begin{equation}
should have its own line and not be at the end of some line. A problem arises, when there is only whitespace on the current line before the cursor. In this case, the begin{equation}
should be inserted in the same line, since the line is empty modulo whitespace.
But instead - I assume because the cursor is not at the beginning of the line, since there is whitespace before it - a new line gets inserted, creating a completely empty line between the text before and the begin{equation}
.
This empty line is a problem, because Latex then interprets this as a new paragraph and inserts extra space between the text and the environment, e.g. the equation. (Also for aesthetic- and clarity-reasons in the .tex file, but those are secondary.)
This problem gets enhanced, because Auctex creates these whitespaces automatically, when creating a new line in the .tex file inside an environment.
Hi,
when I try to insert a subscript in the middle of math formula, it does not get inserted correctly. Here is an image of what happens: wrong_subscript . You can see that the second subscript 'T' is not placed correctly. I am using org mode.
Command "spl" for environment "split" is defined in https://github.com/cdominik/cdlatex/blob/master/cdlatex.el#L1470 as active in text-mode. This environment works only in the math mode and the correct definition, I believe, should be
("spl" "Insert SPLIT environment template" "" cdlatex-environment ("split") nil t)
(values of TEXTFLAG and MATHFLAG in the current definition switched). I am using this definition in cdlatex-command-alist
, and it works as it should.
For odd reasons cdlatex
breaks when inserting an environment in a temporary file. This is annoyting when testing features for e.g. org
development.
Example
(with-temp-buffer
(require 'reftex)
(cdlatex-environment "equation"))
Hi,
I used cdlatex a few years ago for writing tex documents.
Now, some years later I am having a slightly different setup based on spacemacs
and writing the documents in orgmode using company and yasnippets.
I would like to combine orgmode with company, yasnippets and cdlatex.
So in orgmode I would like to activate cdlatex only in math regions. And the
best setup (1.) would complete any available cdlatex snippet, before any yasnippet
and before everything else.
But I would be happy if a simpler approach works as well, e.g.:
(2.) Turn off company and yasnippets in a math region completely
(3.) Turn off only company in a math region completely
I found the doom setup from benneti, which seems to do exactly this:
https://cloud.tissot.de/gitea/benneti/dotfiles/src/branch/master/.config/doom/custom
Unfortunately, I am not able to transfer it to the spacemacs settings :-(
Does anyone have some hints how to achieve the three different setups?
That would be great!
Thank you in advance!
Fab
Hi
\vec is included in the code, but I don't see any keybinding to it.
what do I miss
Uwe Brauer
For now, the default figure
and figure*
environments are structured like
\begin{figure}[htbp]
\centerline{\includegraphics[]{xxxxxxx}}
\caption[]{\label{xxxx} }
\end{figure}
I would suggest changing the default to like
\begin{figure}[htbp]
\centering
\includegraphics[]{xxxxxxxx}
\caption[]{}
\label{xxxx}
\end{figure}
which seems more popular.
I'm not a LaTeX expert, but \centerline
seems not a good option here?
Or, is there an easy way to customize the environment?
I noticed with both cdlatex and org-cdlatex that adding any kind of hat to a capital J produces \Jmath
, for example $\vec{\Jmath}$
.
I couldn't find any mention of this latex symbol existing in any package and from looking into cdlatex-math-symbol-alist-default I don't think it's meant to happen.
It's reproducible with emacs -q
(I have GNU Emacs 29.0.50).
I tried overwriting the definition by copying the definition of j and changing it to keep J being J, but that didn't do anything:
( ?j ("" "\\jmath"))
( ?J ("" "J"))
(Otherwise, thanks for this immensely annoyance-saving package.)
I am using doom emacs, and I for some time now I cannot configure correctly cdlatex to work properly. It seems that every time I upgrade doom, cdlatex operates differently and I am not sure why. The main problem is that the snippets do not work properly, namely equ-TAB
does not insert an equation environment, and fr-TAB
does not put in \frac{}{}
etc.
It seems to me that my problem is company
mode which overrides the cdlatex
. Is there a way to make cdlatex
override the company
mode? One way is to disable company
mode for org mode documents, but I am not sure how to do that.
At the moment my configuration is this:
:lang
(latex
+latexmk
+cdlatex)
(org +roam)
(after! org (add-hook 'org-mode-hook 'turn-on-org-cdlatex))
(map! :after org
:map org-cdlatex-mode
"TAB" #'cdlatex-tab)
(after! cdlatex
(setq cdlatex-use-dollar-to-ensure-math t)
(map! :map cdlatex-mode-map
:i "TAB" #'cdlatex-tab))
I would love to finally understand how this should be set.
Hello, thank you for the package :)
As others have noted before, cdlatex tends to interfere with smartparens. As was discussed in those issues, I have set cdlatex-takeover-parenthesis
and cdlatex-takeover-dollar
to nil
. However, still upon opening a latex buffer, cdlatex interferes with smartparens pair and so on.
I can try and come up with a minimal reproducible config if needed.
Emacs version: 29.1
OS: Linux (Debian 12)
expected result : \textit{foo}
effective result : \textit{foo
The closing curly brace is missing with the message: Symbol's function definition is void: savedpos
Often in mathematics, the interior of a set is noted by a small circle above the set. In Latex, this can be achieved by the command mathring
. I for myself have added an entry to the cdlatex-math-modify-alist
, which adds the command mathring
to the key o
. (I chose o, because o kind of looks like a circle, but of course you could choose whatever key you want.)
Maybe you would want to add it to the default list, because from what I know, it is standard notation and I assume that more people would benefit from it.
Best regards!
Hi,
Could you add cdlatex
to gnu elpa
since it's a partial org
dependency? Or even org-elpa
?
Also, I guess you should add something like this:
;; Package-Requires: ((auctex "11.85"))
Or some other version of auctex with texmathp.el
.
I found the faq to input ` (#70) but the typical situation is that I press ` to input it while foget it would get into the math symbol list, and have to esc and ctrl-q, both of which are not easy to press.
I would like to press ```p to input `', and tried to conifg the cdlatex-math-symbol-alist with:
(112 ("π" "ϖ" "`'"))
But it gives \(`'\) instead of `'. Is there a way to get `'?
Emacs 27 complains about cl being depreciated, as I understand it simply changing from cl to cl-lib should solve this.
I'm using cdlatex in org-mode, and I'm absolutely loving it so far! However, one quirk I noticed that I tend to run into often is that I'm sometimes in a situation like:
\(x \left(y + z|\right)\)
% ^ cursor
After pressing tab, I'd expect my cursor to move to:
\(x \left(y + z\right)|\)
% ^ cursor
so that I can continue writing my latex expression after the parenthesis. However, what actually happens is that the cursor moves to:
\(x \left(y + z\right)\)|
% ^ cursor
so I have to move it back to continue writing.
I managed to trace this issue down to this line. From my relatively weak understanding of regex & my own observation, I came to the conclusion that the code is supposed to break out if any of the characters in "^_[{(" follow the cursor, but one of the escape sequences \\
is adding the backslash character to that list. These escape sequences seem to not be necessary, and are not used in other parts of the code (like here). I got rid of them, and then tested the regex on its own in a buffer and by using cdlatex-tab
, and it all seems to work fine. Let me know if you agree with this analysis.
I'll also go ahead and make a PR to get rid of these backslashes. Would love to see this be patched if it is a bug! 😄
Hello, me again :)
When trying to quickly write out some maths whenever I type a (latin/greek) letter followed by a numeral, 95% of the time I'm doing a subscript (e.g. x
and 0
to make x_0
). Something I have tried (in another editor) and found very convenient is having a numeral immediately following a letter/symbol automatically form a subscript, (i.e. x0
→ x_0
, and x11
→ x_{11}
).
If it would be possible to have this functionality in cdlatex that would be marvellous!
Thanks 😃
I need to disable cdlatex-mode
entirely to make the functionality of LaTeX-electric-left-right-brace
seen here work. I've tried setting cdlatex-takeover-parenthesis
to nil
, but that doesn't solve the problem. It would be nice if I could still insert commonly used pairs like \[\]
and \bigl(\bigr)
with cdlatex-mode
enabled.
It is often the case, that one writes a mathematical expression and then later needs to put the whole expression in some kind of bracket. (e.g. a normal "\left(" "\right)" pair, or an absolute value "|"). For commands like "\underbrace{}" or "\overline{}" this is implemented in cdlatex via the math-modify command '.
It would come in handy, if one could do the same for the brackets: Mark text, and type '( or '[ or '{ or '| r '< in order to insert the corresponding brackets.
If there is some other way to quickly insert Latex-Brackets around marked text, that I am unaware of, I retract this feature-request and would appreciate it, being told this way.
Edit: The variable cdlatex-paired-parens makes sure, that the brackets in the string get automatically inserted as pairs: When one types ( the corresponding ) get's inserted. It would be good, if - as in the "electric-pair-mode" of plain Emacs - also, when marking text, the corresponding brackets get inserted around that text, such that, when marking "text" and pressing "[" then "[text]" would be the result.
The command that is designed to "ease" the use of curly braces, that automatically adds a closing pair, is one that should not override the smartparens
or autopair
functions. The reason being that
cdlatex
' s implementation is not at feature parity (it ignores selection)I am trying to move to doom emacs from spacemacs, and I cannot make cdlatex
work on a latex
mode.
What could be the problem?
I have this in 'init.el`
(latex
+latexmk
+cdlatex) ; writing papers in Emacs has never been so fun
I have this in config.el
(after! latex
:commands (turn-on-cdlatex))
When I try to enter e.g. equation environment with equ
and TAB
it does not work...
Is tab supposed to jump past backslashes? If I tab on this expression \(a^{b}\)
with my cursor after b, I end up outside the math environment. A similar problem happens if I press tab before a closing bracket following by a backslash.
cdlatex
inserts a newline unless the point is bolp
. However, as long as there's only whitespace when looking backward cdlatex
shouldn't insert a newline.
Expected outcome
(equal
(with-temp-file "/tmp/cd1"
(write-file "/tmp/cd1")
(cdlatex-environment "equation")
(buffer-string))
(with-temp-file "/tmp/cd2"
(write-file "/tmp/cd2")
(insert " ")
(buffer-string)))
When I use CDLatex-environments that contain an AUTOFILE insertion, like figure
, then the insertion ends with the following error message:
cdlatex-environment: Wrong type argument: commandp, cdlatexi-nsert-filename
Seems to be a simple typo, but I don't know where.
Hello,
Particularly regarding cdlatex-dollar
, which (no surprise) likes to insert $ ... $
. Unfortunately for LaTeX this is outdated syntax, and \( ... \)
and \[ ... \]
would be greatly preferred.
Thanks :)
p.s. If you want to see why this would be worth doing, there are some good SE questions.
When I press `, I get the available math symbols list, and ` will cyle the list. I could not input in text with this mark ` e.g. in double or single quation ``''. Thanks.
On Ubuntu 20.04.3 LTS, I use the self-compiled git master version of Emacs and installed AUCTeX, company-math, cdlatex, etc. as a LaTeX-based document preparation environment.
But I still found there are some LaTeX commands, such as \boldsymbol
and \hspace
, which can't completed automatically when I type some of their opening characters.
See here for relevant discussion. Any hints for solving this problem?
Regards,
HZ
When using the feature, which inserts a "\rm", when typing '_' or '^' twice, (which worked fine), I got an compiling error stating "Class scrartcl Error: undefined old font command '\rm'.".
Further research yielded the result, that the commands "\rm", "\bf" and "\it" should never be used in Latex2ε and instead their newer versions "\rmfamily", "\bfseries" and "\itshape" should be used. The KomaScript-Classes even enforce this behaviour and thus lead to this error.
However, "\rmfamily" does not work in math mode, while "\mathrm" does. Because of this, I suggest, changing the "\rm" to a "\mathrm". This should be fine in most cases and be the prefered solution.
Thank you!
I am trying to use yas-snippet inside inline math mode like: $inline math mode$
.
When my cursor is in between two $
chars, i.e. $|$
, then the snippet cannot be expanded.
But, if I put in a whitespace (or any other character): $ |$
, it does get expanded.
When I am in an equation environment as \begin{equation} ... \end{\equation}
the snippet gets expanded all the time.
What could be the problem?
It would be useful if cdlatex-environment
emitted some non-nil value when an enviornment is in fact chosen. E.g. to clean-up if cdlatex-environment
was cancelled midway through.
On-thy-fly help writes to the buffer *CDLaTeX Help*
. However, if the user previously ran cdlatex-command-help
, the help buffer preexists and is read-only, which causes on-the-fly help to terminate with the error Buffer is read-only: #<buffer *CDLaTeX Help*>
To reproduce:
M-x cdlatex-command-help
`
Because *CDLaTeX Help*
begins with a space, it's slightly hard to delete as it's hidden in list-buffers
.
Issue originally seen in Emacs 26.1 on Debian Linux but appears to be generic.
When I type j
'
>
instead of the expected \vec{j}
there appears \vec{\jmath}
.
The same is also true for other commands such as \dot, or \interior, but strangely not for \overbar.
As far as I see, this is not the case for other letters, but just j
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.