Registered Member
|
I was wondering of there's a way for Okular to open in a new instance if and only if the file I am trying to open is not already active within another instance of Okular.
For example, if I open file A in Okular, go about my business, and then try to open file A again with Okular, I want it to recognize that I've already opened an instance of file A, and simply reload the file in that opened instance (rather than creating a new Okular window and then having two opened instances of the same file A). At first I thought the --unique flag would work, but then if I have file A opened and I open file B, it takes the place of file A, and file A is no longer open in any instance of Okular. My reason for wanting to do this is for use with Kile. When I compile and view my PDF/DVI, I want Okular to open an new instance if and only if the file I'm trying to view is not already being viewed. If it's already open, I want it to just reload the current version of the file. Evince does this quite nicely, however I can't use the wonderful forward/inverse search options with my LaTeX code if I'm pairing Kile and Evince, so I need to force Okular to do exactly what I want. Perhaps there's a way to call a script/user-defined application that handles this functionality, and have the script in turn call Okular? It seems like this could be a quick and dirty fix, but I'm not very adept with scripting, so if anyone could suggest a script or suggest a place I could look to learn how to do this (provided there's no easier fix that I'm overlooking), I'd greatly appreciate it! Thanks --Brock |
Registered Member
|
Hi,
Probably, what you want to do is asking Kile to just compile your document, and not open the compiled document. Indeed, if the document is open in Okular and modified, Okular will detect it and reload it automatically. Hope this helps! Cheers, Martin. |
Registered Member
|
Sorry for digging up this old post. I have a custom script that generates my latex files and so had the same problem. Here is my fix in case anybody comes across the same problem:
|
Registered Member
|
Hi arnom and others,
I have been very happy to find the trick that is just a few days old! To make it work between kile and Okular, I adjusted the script a little - Kile automatically adds the "pdf" ending, and if pdfLaTeX is set to "Modern", it also adds information for the forward and inverse search. My script currently reads as follows:
Functionality which I can achieve: * forward search on the first compilation of a file (i.e. the pdf opens roughly on the position which you have been editing before you hit "compile"), * reloading the file on any successive compilation, * separate Okular window for each pdf file, * inverse search for all files (i.e. Shift+LeftMouseClick within Okular gets you to the relevant place in the tex source). I did not achieve forward search on recompilation of a given file, and I sincerely think it cannot be done (with Kile 2.0.85 and Okular 0.10.5 at least - these are not the newest versions available though!) The script also does not work with ViewDVI or ViewPDF (Okular has to be called through ForwardDVI or ForwardPDF to work with the above script). A step by step descriptin how to get that funcitonality (for those that have not set up forward and inverse search previously): * save the above code into a file, e.g. ~/bin/okular_unique_per_file.sh * chmod +x ~/bin/okular_unique_per_file.sh * in Kile, go to Settings -> Configure Kile -> Tools/Build - choose ForwardPDF, create New_Okular (and make sure it is selected) Command:~/bin/okular_unique_per_file.sh Options: '%absolute_target' - similarly, create new version of ForwardDVI, and select it - select the Modern variant of PdfLaTeX and PdfTeX so that the options read -synctex=1 -interaction=nonstopmode '%source' - and also select the Modern variant of TeX and LaTeX, so that the options read -src-specials -interaction=nonstopmode '%source' - make sure that in QuickBuild, ForwardPDF/ForwardDVI is used (and not ViewPDF/ViewDVI) * in Okular, go to Settings -> Configure Okular -> Editor and choose or set it so that it reads kile %f --line %l Good luck! Anša |
Global Moderator
|
Hmm, for me okular just reloads changed files automatically... so if I'm working with LaTeX, I just recompile my document and then it reloads the document by itself. But I see you found a solution for your issue too
I'm working on the KDevelop IDE.
|
Registered Member
|
My Okular also reloads the files automatically, but that does not include forward search (jumping to the position in the pdf that corresponds to the position I am editing in Kile). The script above actually uses this functionality of Okular (it only calls Okular if the file is not open in it yet).
So if I am using the script above for working with several files simultaneously and I suddenly start editing a different part of the same file, I have to scroll in Okular to a new spot. If forward search would work properly, I would not have to scroll Needless to say, forward search is working perfectly in the Okular --unique mode that is provided by Kile (but which opens all files in one window). |
Registered Member
|
I seem to be having the same problem. I do not use Kubuntu, only Ubuntu with gnome desktop. When I double click a pdf file in Nautilus, it opens with Okular, which I have set as default. However, if I double click on it again, it opens another instance of the same file. I checked /usr/share/applications/kde4/okular.desktop and it does not have the --unique or --multiple flags set. It used to work earlier before I installed Kile and changed the .desktop file for kile in order to add %U to make it my default program to open .tex files.
Reinstalling after removing all my kde applications (with the purge flag set so that it also removes other customizations) did not help either. Can someone give me instructions on how to run the script that has been suggested here as a work-around? After making it executable with chmod +x, what should I do? Edit the .bashrc file? (Note that I want it to work when I open it from the file browser, and the suggested fix of running it with --unique from Kile already works.) |
Administrator
|
If you want it to work from the file browser, then you need to use a menu editor. In KDE you could use KMenuEdit - I do not know if GNOME has a similar alternative. Once the menu entry is changed, the file association will automatically change as well.
KDE Sysadmin
[img]content/bcooksley_sig.png[/img] |
Registered Member
|
I've improved the script posted above. Now I can do proper forward search from Kile without getting lots and lots of open copies of Okular with the same file. The idea is: kill all instances of Okular that run the file which you are about to open.
This only works if Okular is not running in the "Open new files in tabs" mode - I do not know how to find out if a file is open in a tab, nor how to close a specific tab from an outside script. But it works fine when all files are opened in new instances of Okular.
|
Registered users: Bing [Bot], daret, Google [Bot], Sogou [Bot]