24

I use LyX 2.0.4 (on Mac OS 10.7) and would like it to do the following:

whenever I hit "View" it should automatically save the pdf output of the lyx file in the same folder the lyx file resides. Whenever I hit "View" again it should overwrite the older version of the pdf. Is that possible?

This is similar to the behavior I know from TeXShop.

Michael
  • 622

3 Answers3

20

The following should work on LyX >= 2.3.1 for all operating systems:

First go to Tools > Preferences > Output and change "Overwrite on export" to "All files". Make sure you know what that means and that you are comfortable with that. Apply that preference change.

Then go to Help > About to find out where your "Library directory" and "User directory" are. For example, mine are

library directory: /usr/share/lyx

and

user directory: ~/.lyx/

Navigate (e.g. in your file browser) to your library directory and go to the ui folder and copy stdtoolbars.inc to the ui folder of your user directory. So in my case I copied /usr/share/lyx/ui/stdtoolbars.inc to ~/.lyx/ui/stdtoolbars.inc

Now edit stdtoolbars.inc in your user directory: You want to edit the line below

Toolbar "view/update" "View/Update"

Change

Item "View" "buffer-view"

to

Item "View" "command-sequence buffer-view pdf2; buffer-export pdf2"

If you want to know more, read the LyX help guides in the Help menu for more customization.

scottkosty
  • 13,164
  • +1 for the cool idea to implement this on the UI level by a simple command sequence – Daniel Sep 12 '12 at 09:17
  • Thanks a for the detailed instructions. Unfortunately after following the steps and hitting view on a file I get the message "SIGSEGV signal caught! Sorry, you have found a bug in LyX..." and thereafter LyX crashes each time I hit view. But the problem dissapears if I delete the stdtoolbars.inc file and undo the setting. Guess I'll have to send a bug report. – Michael Sep 13 '12 at 14:43
  • @Michael do you also get that message if you use that command in the mini-buffer? Type alt-x and then paste command-sequence buffer-view; buffer-export pdf2 and press return. – scottkosty Sep 13 '12 at 16:18
  • Thanks for your continued interest. I just tried what you suggested but it crashed again (this time on a different Mac running OS 10.8 with LyX 2.0.0). Didn't give me the error message though. Might be a Mac related problem? – Michael Sep 13 '12 at 18:48
  • @Michael yes, it might be. I might be at fault for suggesting you run these commands. LyX allows for a lot of customization and with that freedom sometimes comes a price. If you're up for it, I'd suggest you try one more thing: switch the order, so try running command-sequence buffer-export pdf2; buffer-view – scottkosty Sep 13 '12 at 19:25
  • The new order didn't cause a crash and saved the pdf in the same folder, but it didn't show the pdf. If I only enter buffer-view it does show it. – Michael Sep 14 '12 at 10:20
  • Ok, it's somehow not behaving consistently: I tried the original order of command right after the new suggestion and it seemed to work just fine (displaying and saving), but as soon as I executed it again it crashed. – Michael Sep 14 '12 at 10:50
  • @Michael OK, I can't reproduce this on Ubuntu so I guess all we can do is follow the bug report. If there is no activity there for another few days, I will ask on the development mailing list if Mac users can reproduce. The only other thing you could do besides waiting would be to produce a back trace. This would involve some work, but I wanted to throw that out there in case this is very important to you. I'm not sure how to produce a back trace on Mac, but I'm guessing you need to be able build and then use gdb. Also note that any fix for this crash wouldn't be released for a few months. – scottkosty Sep 14 '12 at 15:24
  • Dear scottkosty, it is not so urgent at the moment. Thanks again for your help. – Michael Sep 14 '12 at 19:46
  • @Michael OK sounds good. I post any updates here. – scottkosty Sep 14 '12 at 19:47
  • Hi, I don't always get crashes with this method (Lyx 2.0.5.1), which is good, but I have the following problem. The View toolbar item loses its icon which is replaced by the text "View", and it doesn't display the shortcut anymore in brackets. Even after I modify the shortcut ⌘R to execute the same new command. Thoughts? – Dan Apr 01 '13 at 14:36
  • @Dan the name of the button has to be the same as the command. I don't know how this works for command-sequence. See the lib/images folder in the library directory of LyX. – scottkosty Apr 01 '13 at 18:15
  • 1
    This site suggests command-sequence buffer-view pdf2 ; buffer-export pdf2 ; It works for me without crash (Lyx 2.1.4, Mac El Capitan) – T_T Aug 26 '16 at 07:13
  • @T_T thanks for the comment. It does seem like a good idea to specify the pdf2 for buffer-view since it is specified for buffer-export. I made this change to the answer. – scottkosty Aug 26 '16 at 21:45
  • 1
    This crash has been fixed as of LyX version 2.3.1 (see https://www.lyx.org/trac/ticket/8338). – scottkosty Jul 13 '20 at 17:55
10

Alternative workaround: map buffer-export pdf2 to a keyboard shortcut in Editing->Shortcuts in Preferences.

How to use it: Preview in OS X (and many other pdf viewers as well) will update open pdf's whenever they are changed, so, if you just run the export command once and then open the pdf and leave it open, every time you run the export command again the pdf will get updated. I usually have my windows arranged such that I can see LyX and Preview at the same time, so this works out almost as well as having LyX actually open the pdf (like it does when you run the "View" command -- which somehow renders and opens the pdf without crashing LyX...).

Why use this method: As was the case for Michael, in OS X LyX randomly crashes when I try to do command-sequence buffer-view; buffer-export pdf2 as suggested by @scottkosty. It seems that some other users are able to use the sequence without crashing, so it might be best try that first. The workaround given here isn't exactly what Michael asked for because LyX does not open the pdf, but it is the closest I have been able to get that works without crashing.

ws_e_c421
  • 401
  • I've talked with LyX developers about this and this is the approach they recommend. – badp May 10 '13 at 14:31
  • Please don't start answers with "I have the same issue". People might think you don't post a solution but a "me too" post instead. – Martin Scharrer May 11 '13 at 09:26
4

This only changes the behaviour for the keyboard shortcut, not the gui icon. It's easier and maybe all you need.

First go to Tools > Preferences > Output and change "Overwrite on export" to "All files". Make sure you know what that means and that you are comfortable with that.

Then go to Tools > Preferences > Editing > Shortcuts, search for buffer-view Ctr-R, click modify and replace buffer-view with command-sequence buffer-view pdf2; buffer-export pdf2.

Nobody
  • 153