Re: Standalone Math Editor
Le 20/02/2017 à 07:44, Wei-Ting Lin a écrit : Thanks a lot! I'm trying Lyxserver and Lyx functions. They are amazing. I can just send commands to open a document and insert a display math! One problem seems that there is no Lyx function allowing me to get the content of math. I can use select and copy to put it into clipboard, then maybe read the clipboard to get the content. This seems not very elegant and reliable? I suggest creating a new LFUN that would be handled by InsetMathHull (the topmost math inset). Commit e91572a0 will show you an example for adding a new LFUN. Instead of GuiView::dispatch and GuiView::getStatus you are looking to add to the equivalent methods of InsetMathHull. InsetMathHull::write gives you the LaTeX code for the math inside the inset. Now what I don't know personally is how to send the result back via the lyx server. Guillaume
Re: Standalone Math Editor
Thanks a lot! I'm trying Lyxserver and Lyx functions. They are amazing. I can just send commands to open a document and insert a display math! One problem seems that there is no Lyx function allowing me to get the content of math. I can use select and copy to put it into clipboard, then maybe read the clipboard to get the content. This seems not very elegant and reliable? Another problem is that I don't know how to return to the editor. That seems a much harder problem. Wei-Ting
Re: Standalone Math Editor
Le 18/02/2017 à 06:44, Guenter Milde a écrit : On 2017-02-18, Wei-Ting Lin wrote: Your suggestions are valuable and important for me. I never think Lyx is not lightweight. Actually, I'm always satisfied with its speed. I just think to type math equations we don't need a full Lyx. But you're right. The first step should be the input/output function. I'm thinking to implement the following function: (1)When I'm editing an equation, say \[ f(x)= \], I can open Lyx with, say Ctrl+C. (2)Lyx is initiated with a display math mode, so I can edit the equation. (3)After finishing editing, push some keybinding to hide the Lyx window and return the Latex code to the editor. (4)The editor can receive the Latex code and insert it into my file. I think (1) and (4) involve the editor's functions, and should be put aside at the beginning. For (2) and (3), do you have any suggestions? I've checked the source code, and kind of overwhelmed. For 2), you can write a template file and open lyx with that. I don't see a "--new-from" (or similar) command line option, so this seems like a task for the "lyxserver"¹. 3) hiding the lyx window is a function for the window manager, again the lyxserver may help. pushing the content to the clipboard would be simply: command-sequence; select-all; copy; Alternatively, the lyxpipe can receive the content. In addition, I am thinking about a LFUN that sends the LaTeX contents of the math hull at the cursor location to wherever LyX has been instructed to at step 2) (and will do the closing/hiding). What I am not familiar with is the lyxserver side.
Re: Standalone Math Editor
Wei-Ting Lin wrote: > I have no idea where to start from. Yeah, that will take a little time. Attached are few patches I used some time ago when I created quick and dirty lyx math calculator which launches external app (maxima) when equation is finished. I don't think you can apply those patches right away with nowadays master, but at least they might give you few inspirational points what and where to touch few things. No IO there though. Pavel commit 5ede0161b732f33426535c0e467b0ed43093d26c Author: Pavel SandaDate: Mon May 16 22:26:49 2011 +0200 Revert my older commit in branch which allows usage of command alternatives inside mathull. We should migrate to user binding instead of enter hardcoding one non lazy day. diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp index b28142c..fde47dd 100644 --- a/src/mathed/InsetMathHull.cpp +++ b/src/mathed/InsetMathHull.cpp @@ -1549,11 +1549,6 @@ bool InsetMathHull::getStatus(Cursor & cur, FuncRequest const & cmd, status.setEnabled(true); return true; - // we never allow this in math, and we want to bind enter - // to another actions in command-alternatives - case LFUN_BREAK_PARAGRAPH: - status.setEnabled(false); - return true; case LFUN_MATH_MUTATE: { HullType const ht = hullType(cmd.argument()); status.setOnOff(type_ == ht); commit c628b6cb6510a23f85d6f4840402617c39a41a5d Author: Pavel Sanda Date: Sat Dec 11 18:33:43 2010 +0100 More general esc diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp index 8ffd80c..5a835fb 100644 --- a/src/mathed/InsetMathNest.cpp +++ b/src/mathed/InsetMathNest.cpp @@ -834,7 +834,7 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd) else { //cmd = FuncRequest(LFUN_FINISHED_FORWARD); //cur.undispatched(); - lyx::dispatch(FuncRequest(LFUN_COMMAND_SEQUENCE, "inset-select-all;char-delete-backward;math-mode on")); + lyx::dispatch(FuncRequest(LFUN_COMMAND_SEQUENCE, "buffer-begin;buffer-end-select;char-delete-backward;math-mode on")); } break; commit 058b2d6c52ab270282081d9791651873f50922ed Author: Pavel Sanda Date: Sat Dec 11 17:22:42 2010 +0100 Allow smaller size of window diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index e30ad41..8bd7a34 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -491,7 +491,7 @@ GuiView::GuiView(int id) // Forbid too small unresizable window because it can happen // with some window manager under X11. - setMinimumSize(300, 200); + setMinimumSize(30, 20); if (lyxrc.allow_geometry_session) { // Now take care of session management. commit a637afc3a9874418277a24bd4630e074031eb07e Author: Pavel Sanda Date: Sat Dec 11 16:59:14 2010 +0100 Escape for reseting calc diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp index 21bfdfe..8ffd80c 100644 --- a/src/mathed/InsetMathNest.cpp +++ b/src/mathed/InsetMathNest.cpp @@ -832,8 +832,9 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd) if (cur.selection()) cur.clearSelection(); else { - cmd = FuncRequest(LFUN_FINISHED_FORWARD); - cur.undispatched(); + //cmd = FuncRequest(LFUN_FINISHED_FORWARD); + //cur.undispatched(); + lyx::dispatch(FuncRequest(LFUN_COMMAND_SEQUENCE, "inset-select-all;char-delete-backward;math-mode on")); } break; commit e23a7c369a6012322810e35065962113cc253403 Author: Pavel Sanda Date: Sat Dec 11 16:44:59 2010 +0100 Do not ask for save at the end diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index 04b3ce9..e30ad41 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -2474,6 +2474,7 @@ bool GuiView::closeBuffer(Buffer & buf) // so no need to do it here. This will ensure that the children end up // in the session file in the correct order. If we close the master // buffer, we can close or release the child buffers here too. + lyx::dispatch(FuncRequest(LFUN_BUFFER_WRITE)); bool success = true; if (!closing_) { ListOfBuffers clist = buf.getChildren(); commit 8b3431e29ab5eae0a28e479507f323341a2a6039 Author: Pavel Sanda Date: Sat Dec 11 16:18:19 2010 +0100 Setup new window and proper inset diff --git a/src/LyX.cpp b/src/LyX.cpp index 5ae488d..fbcb8ca 100644 --- a/src/LyX.cpp +++
Re: Standalone Math Editor
On 2017-02-18, Wei-Ting Lin wrote: > Your suggestions are valuable and important for me. > I never think Lyx is not lightweight. Actually, I'm always satisfied > with its speed. I just think to type math equations we don't need a > full Lyx. But you're right. The first step should be the input/output > function. > I'm thinking to implement the following function: > (1)When I'm editing an equation, say \[ f(x)= \], I can open Lyx with, > say Ctrl+C. > (2)Lyx is initiated with a display math mode, so I can edit the equation. > (3)After finishing editing, push some keybinding to hide the Lyx > window and return the Latex code to the editor. > (4)The editor can receive the Latex code and insert it into my file. > I think (1) and (4) involve the editor's functions, and should be put > aside at the beginning. > For (2) and (3), do you have any suggestions? I've checked the source > code, and kind of overwhelmed. For 2), you can write a template file and open lyx with that. I don't see a "--new-from" (or similar) command line option, so this seems like a task for the "lyxserver"¹. 3) hiding the lyx window is a function for the window manager, again the lyxserver may help. pushing the content to the clipboard would be simply: command-sequence; select-all; copy; Alternatively, the lyxpipe can receive the content. ¹ the lyxserver is an API to "remote control" LyX via pipes taking LFUNs (inpipe) and giving out informative or task/content-related output. On the lyx wiki, there is a Python class to interact with LyX via the lyxserver. https://wiki.lyx.org/Tools/PyClient Günter
Re: Standalone Math Editor
Thank you Guillaume. Your suggestions are valuable and important for me. I never think Lyx is not lightweight. Actually, I'm always satisfied with its speed. I just think to type math equations we don't need a full Lyx. But you're right. The first step should be the input/output function. I'm thinking to implement the following function: (1)When I'm editing an equation, say \[ f(x)= \], I can open Lyx with, say Ctrl+C. (2)Lyx is initiated with a display math mode, so I can edit the equation. (3)After finishing editing, push some keybinding to hide the Lyx window and return the Latex code to the editor. (4)The editor can receive the Latex code and insert it into my file. I think (1) and (4) involve the editor's functions, and should be put aside at the beginning. For (2) and (3), do you have any suggestions? I've checked the source code, and kind of overwhelmed. I have no idea where to start from. Thank you, Wei-Ting
Re: Standalone Math Editor
Le 17/02/2017 à 07:17, Wei-Ting Lin a écrit : Hi all, I have used Lyx for several years. This is a really amazing software. However, many people still write LaTex with text editors. That usually means when we cowork on some article, we have to write LaTex directly. This is ok. However, sometimes we have very long and complicated equations. One of amazing features of Lyx is its math editor. This makes the equation visible, when you're editing. That has helped me a lot. Therefore, I'm thinking if it is possible to separate the math editor, as a standalone, lightweight editor. I'm also thinking if it is possible to call the editor from vim, emacs or whatever, when we need to edit an equation, and then return the LaTex code back to vim or emacs. It seems there is no such work yet. I'm wondering how difficulty to implement this. If this is not too hard, I would like to try to do it. Thank you very much, Wei-Ting Dear Wei-Ting, Using LyX as a stand-alone math editor is definitely feasible. The key design that makes this possible is that for math, LyX directly reads and writes LaTeX code (unlike for the text). Essentially you would get what you can already do by copy-pasting LaTeX math into LyX math and copying the LaTeX preview back into your document. I would be happy to see such a feature implemented. It should be easy to implement basic input/output (what you call "call the editor and then return"). Then there would be some moderate effort for the UI/cosmetics ("separate the math editor"). As for "lightweight": LyX is already pretty quick; start-up is slow but this could be improved a lot with a small amount of work to fix a few known bottlenecks. Lastly, some LaTeX features are currently unsupported, but nothing opposes that they could get implemented over time. If you manage to get started with a prototype for the input/output aspects, the rest will follow from there (in particular the cosmetic aspects, which can be time-consuming and are best left to an ulterior time). Assume for instance that you want to use a tex file containing the math equation as the medium between your text editor and LyX. Essentially LaTeX import works fine in this case, and what you want to do on the LyX side is make it convenient to write the LaTeX math back into the original tex file. Do not hesitate to ask for directions. Sincerely, Guillaume