[Lowerbounds, Upperbounds]

Algorithms are everywhere.

(Most recently updated on 2008-02-08, but I have kept the referenced MiKTeX version at 2.5. As far as I know, none of the changes in MiKTeX 2.6 and 2.7 matters to the topic of this post.)

I have recently upgraded my MiKTeX to the latest version 2.5 for some reason. And as much as I love MiKTeX, I have switched from YAP (Yet Another Previewer, the DVI previewer in MiKTeX) to Dviout.

Dviout may not be very familiar to non-Japanese users because, to my understanding, it is primarily developed to deal with Japanese usage (think about fonts). However, it works equally well in English too. I can recommend Dviout over YAP 2.5 for several reasons:

  • Dviout pretty much does everything YAP is capable of: color specials, HyperTeX jumps (you use the hyperref package, don’t you?), and perhaps most importantly, round-tripping using source specials (but see the note below).
  • Unlike YAP 2.5, it does not seem to have any DVI locking issue, at least not in my daily usage of working on a large document. (To me, this alone is worth the switch until YAP eliminates the lock issue.)
  • In my experience, Dviout is much faster than YAP ever since it had a major change in version 2.5. Unlike YAP, Dviout does not make you choose between “dvips” vs “pk font” rendering—the former is slow, and the latter cannot be used when your document has any graphics. There is really no good choice in YAP.
  • The particular document I am working with is also somewhat graphics intensive. Like YAP, Dviout is able to call Ghostscript to show the included graphics in the DVI preview. But it also caches the generated bitmaps and use them later for unmodified figures. This saves me a lot of time. (And this is the primary reason why I expect to stick with Dviout for a while. I sprinkle \parpics and wrapfigures quite liberally on my spaghetti.)
  • Dviout allows you to customize the shortcut keys. I like to exercise my left hand more often and so I set some shortcuts on my left hand.
  • Dviout can do a text search directly inside DVIs. This can be handy if all you have is a DVI file. (Package documentation comes to mind. And yes, you could have converted it to PS and then do the search in the PS…)

(Note: there is an issue that I am still puzzling on. In the forward search, sometimes Dviout will land on a few paragraphs earlier than the intended destination. I will update this post once I figure out the solution.

Update 2007-03-07: Nailed it. First, recall that source specials are implemented by inserting tags that specify the source file and the corresponding line number into the DVI file. The problem is that sometimes the line numbers in the tags are not in increasing order. Here is how the stream of tags might look like: {src:1003main.tex}{src:1055main.tex}{src:1015main.tex}{src:1019main.tex}. In this case, if you ask the DVI previewer to go to line 1015 of main.tex, a simple scan algorithm will hit the second tag and then incorrectly conclude that no further reading is necessary. This is exactly what happened. Workaround? I guess I will have to wait until I finish my current project and patch the source directly.)

Below I will show how to get Dviout working with MiKTeX 2.5. (Update 2007-11-15: The same instruction works for MiKTeX 2.6 because there is no change in directory layout.)

  1. Remove the directory C:\localtexmf\fonts if you have one. It contains your existing PK font files. We can afford to regenerate them. MiKTeX 2.5 by default put PK files in a different location too.
  2. Create a new file dviout.par and put it in the same directory with dviout.exe. It’s the preference file for Dviout.
  3. I have included the non-default parameters that I use at the end of this post. You can use it as your first dviout.par and start from there. As you can see, there are some hard-coded path names that you will need to change. The following is a list of parameters that you want to pay attention to, in the order of appearance in my dviout.par below:
    GS
    This means “On” with “Direct PS” turned off in the Graphic tab. Keeping Direct PS off can mitigate a class of problems due to dvi files prepared with source specials containing postscript. For instance, you can generate such a dvi file by using hyperref with the dvips driver, which is usually the default. The right driver for dviout is hypertex, used like this \usepackage[hypertex]{hyperref}.
    gsx
    You may have installed Ghostscript somewhere else. I note that MiKTeX comes with Ghoscript these days, but I usually keep an installation of the most recent Ghoscript so I don’t use the one that comes with MiKTeX.
    gdat
    All my documents store their figures in a figure subdirectory. The current setting tells Dviout to cache the preview bitmaps in the same subdirectory instead of the parent directory where the DVI is located.
    gen
    I installed my MiKTeX there. The default for 2.7 would be `C:\Progra~1\miktex~1.7\bin\makepk.exe ^s ^d ^D ^M. There should be no space in the path name and so you must use short path. Also, be careful with the backquote character.
    key
    I have added four shortcut keys to my config. “z” and “x” are for back and forward, “-” and “=” are for zooming out and in. Also, note that “space” is by default mapped to next-page, and so the pair “z” and “space” is all I use most of the time. Remember, the shortcuts are fully configurable in the Option->Set Parameter->Key tab.
    BMP and scale
    I have made an unusual choice here because of my late-night TeXing. The negative numbers represent negative gamma, which is to say that the DVI text is displayed in white on black. If you want the normal black on white, change the -400 to 1100. The particular number depends largely on the font you use and your monitor, but 1100 is in the ball park. (This answers rmcd’s comment.)
    TEXROOT
    For MiKTeX 2.6, the current setting is a sensible choice. This is what ^r in the TEXPK option expands into.
    TEXPK
    If you have installed MiKTeX 2.6 at its default destination, use TEXPK=”^r\fonts\pk\\dpi^d\^s.pk;C:\Program Files\MiKTeX 2.6\fonts\vf\\^s.vf” instead. You can read my comment on 2007-03-23 to understand what it does and how you can come up with the right setting for your machine with the help of YAP.
    TEXFONTS
    According to the Dviout manual, this option is needed when you cannot generate a PK font but you want to replace the missing characters with spaces of the correct size, hence the need to locate the TFM (font metric) files. I would say that if you cannot generate an English PK font, then you want to resolve the issue completely instead of relying on this feature.
    src
    I use GNU Emacs on Windows since a long time ago and I am still at version 21. That explains why I picked gnuclientw as my src editor. In the comments, rmcd explained how to use emacsclient instead. Dviout supports DDE as well and so you can use many other editors. See the help file for instructions.
    gsrc
    I use Ipe for most of my graphics. That explains the path in gsrc.
    isp
    With the GS option above, we have turned off Direct PS. This “ignore some source specials” setting further suppresses a whole bunch of (mostly harmless) warnings. There are pros and cons, but I think this together with the GS setting above is a sensible default.
    file
    This is where you put dviout.par. Of course, you don’t really change this setting by changing it inside dviout.par, but this is a non-default setting with a hardcoded path. :P
  4. Finally, to make AUCTeX use Dviout instead of YAP, here is a snip from my tex-site.el. Note that I am showing you Emacs Lisp here and as rmcd pointed out in his comment, you do not want to enter the backslashes before the two inner double-quotes if you are using Emacs’s customize-variable command to change your TeX-view-style. The backslashes are only necessary in Emacs Lisp so that we escape the two inner double-quotes.

    (setq TeX-view-style
    '(("^a5$" "yap %d -paper a5")
    ("^landscape$" "yap %d -paper a4r -s 4")
    ("^epsf$" "gsview32 %f")
    ;;("." "yap -1 -s%n%b %d")
    ("." "dviout -1 %d \"# %n %b\"")))

Here are some usage tips on Dviout:

  • As much as I prefer not to ask you to touch the registry, you want to know that Dviout remembers some of its settings in HKCU\Software\SHIMA\DVIOUT. For instance, it stores the window dimensions there. (I set my xPos, yPos, Height and Width in the registry once and for all.) I believe that all options set outside of Option->Set Parameters, such as Option->Continuous Renew, are stored in the registry.
  • You may also want to disable Options->Check color specials from the menu in case Dviout complains about your DVI file. It happens when your color specials have certain issues as explained in the manual. I meet these issues too frequently.
  • Make sure you enable Options->Setup Parameters...->System->Auto Renew. (It’s on by default, but it’s worth checking in case you turned it off by accident.) It forces a update check when you switch into Dviout from another application. This behavior is shared among most, if not all, DVI previewers.
  • Options->Continuous Renew is a good thing if you have a large monitor or a dual monitor to let you see both your text editor and Dviout without overlap. This option will cause Dviout to pop into foreground when the DVI file is updated. Using Microsoft’s Tweak UI, in General->Focus, enable Prevent applications from stealing focus and set it to flash the taskbar button one time. That will make Dviout always show you the latest DVI without stealing the focus from your text editor. (I use this with the continuous mode in latexmk.)
  • Most importantly, once you have customized the options using Option->Setup Parameters to your own liking, select Option->Non-default Parameters. A small text box will pop up and you can copy and paste its content into your dviout.par. (That’s how I get the file below.)

Have fun with Dviout!

Finally here is my current dviout.par (last updated 2008-02-08). I have also uploaded it as a file to avoid line wrapping and other funny things due to quotes.

br=0x800000
bf=0x800000
bb=0x1d4c000
multi=4
button=+
dpi=600
GIF=5
GS=17
gsx=C:\Progra~1\gs\gs\bin\gswin32c.exe^-IC:\Progra~1\gs\fonts;C:\Progra~1\gs\gs\lib;C:\Progra~1\gs\gs\Resource^-dTextAlphaBits=4^-dGraphicsAlphaBits=4
gdat=./figures
gsize=+
search=448
sdpi=600
hyper=0x1d030
hbuf=0x400000
ToEdit=^c^V
FB=2
varf=+
gen="`C:\texmf\miktex\bin\makepk.exe ^s ^d ^D ^M"
y=F614.295pt:794.96999ptP
key=DR=-:DM==:JL=x:JF=z
log=C:\temp\dviout.log
BMP=6:6:-400
scale=2:2:-400:4:4:-400:2:2:1100:4:4:1100
TEXROOT="C:\Documents and Settings\All Users\Application Data\MiKTeX\2.6"
TEXPK=^r\fonts\pk\\dpi^d\^s.pk;C:\texmf\fonts\vf\\^s.vf
TEXFONTS=C:\texmf\fonts\tfm\\
src='gnuclientw^s+%d "%s"'
gsrc=.eps.pdf=C:\UnixHome\ipe\bin\ipe.exe^s"%n.ipe"
isp=ps:SDict;!
file=c:\unixhome\dviout\dviout.par

P.S. I should mention that staying with MiKTeX 2.4 would not be a bad choice if I could… You should also be reminded of potential issues if you decide to upgrade to Vista before MiKTeX 2.6 comes out.

26 Comments

  1. AvatarUser
    9:23 on March 23rd, 2007

    Unfortunately, I do not succeed in using dviout with Miktex 2.5
    Can you explain the following parts of your dviout.par:

    TEXPK=^r\fonts\pk\\dpi^d\^s.pk;C:\texmf\fonts\vf\\^s.vf
    src=”gnuclientw^s+%d %s”

    I do not have the c:\texmf directory (this was an old Miktex 2.4 directory). Which one should I use instead?

  2. You can figure out the right TEXPK setting using Yap. Suppose you have foo.dvi and it works in Yap and fails in Dviout.

    Open foo.dvi in Yap. Go to File->Document Properties->Fonts. You will see a dialog box listing all the fonts you use in foo.dvi, with the font names and the corresponding font files. The list may be very long but the items collapse into similar cases. Our job would be to set up TEXPK correctly so that Dviout can find these font files as well.

    As an example, a dvi file that I am currently working on has these two representative items:

    (1) cmr9, C:\Documents and Settings\All Users\Application Data\MiKTeX\2.5\fonts\pk\ljfour\public\cm\dpi600\cmr9.pk

    (2) pbkd8t, C:\texmf\fonts\vf\adobe\bookman\pbkd8t.vf

    To refer to the packed fonts in TEXPK, I simply use “^r\fonts\pk\\dpi^d\^s.pk” because I have already hardcoded “C:\Documents and Settings\All Users\Application Data\MiKTeX\2.5″ into TEXROOT. You can see that this covers case (1) because “^r”, “^d”, “^s” refer to TEXROOT, the DPI and the font name respectively. “\\” in TEXPK means “any subdirectory under this directory” and in case (1) it would be automatically expanded into
    “ljfour\public\cm”.

    To refer to the virtual fonts in TEXPK, I have to specify the full path. That’s why I used “C:\texmf\fonts\vf\\^s.vf”. This covers case (2) on my machine. If you have a fresh default installation of MiKTeX 2.5, I believe you want “C:\Program Files\MiKTeX 2.5\fonts\vf\\^s.sf” instead.

    Hope this helps.

  3. AvatarUser
    19:25 on March 23rd, 2007

    Yiehaa, it works :-)
    Thank you very much!

    I only needed to change “C:\texmf\fonts\vf\\^s.vf” to “C:\Miktex\fonts\vf\\^s.vf”!

    I am so glad to have an alternative for the extremely slow Yap! Thanks again!

  4. AvatarSebastian
    18:26 on April 18th, 2007

    Hi Maverick!

    Thanks for your tips!
    I have one question: When I use forward search and invoke dviout, my mouse cursor jumps in dviout to the spot where the forward search was started in the TeX editor.
    Do you have any idea, whether I can turn this “feature” off?

  5. Hmm, I don’t know of any way to turn this off from the GUI. Sorry. :<

  6. AvatarSteffen
    1:55 on May 28th, 2007

    Hi Maverick!

    I also want to switch from yap to dviout but I use MiKTex 2.6.
    I failed to set it up in the way mentioned above.
    I don’t know how to set the variables TEXROOT and TEXPK in the right way for MikTex 2.6.
    Can anybody help me?

    Regards Steffen

  7. Avatar@@
    2:49 on May 28th, 2007

    Hi Steffen,

    You will find them out in one of the followings ways:
    (1) [Start] => [(S)ettings] => [(C)ontrol Panel] => [System] => [Advanced] => [E(N)vironment Variables] => [(S)ystem variables]
    (2) [Start] => [(R)un] => Open: sysdm.cpl => [Advanced] => [E(N)vironment Variables] => [(S)ystem variables]
    (3) [Start] => [(R)un] => Open: regedit => then find HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
    Hope it helps.

    Sincerely,

    @@

  8. AvatarSteffen
    4:14 on May 28th, 2007

    Hi,

    Thanks for this hint, but unfortunately these environment variables do not exist. Anybody found the right settings for TEXROOT and TEXPK in the dviout.par for MiKTex 2.6?

    Sincerely Steffen

  9. AvatarMaverick Woo
    10:05 on May 28th, 2007

    Hi Steffen,

    The only thing you need to figure out is where you installed MiKTeX. MiKTeX 2.5 and 2.6 are similar enough (unlike the jump from 2.4 to 2.5). Mine happens to be in C:\texmf but that’s because of some legacy reasons.

    If you go with the default in English, I would expect these to work:

    TEXROOT=”C:\Documents and Settings\All Users\Application Data\MiKTeX\2.6″
    TEXPK=”^r\fonts\pk\\dpi^d\^s.pk;C:\Program Files\MiKTeX 2.6\fonts\vf\\^s.vf”

    Again, if dviout fails but yap works for a particular dvi file, you can show us a couple entries of the list in File->Document Properties->Fonts. That will give us a good idea how to set up the variables.

    Hope this helps.

  10. AvatarSteffen
    14:09 on May 29th, 2007

    Hi Maverick,

    Thank you very much, it’s works!

    Can you help me once more?
    I use the psfrag package but I don’t understand the entry in the dviout manual how to set up dviout that it can deal with psfrag commands?

    Thanks in advance!
    Steffen

  11. Sorry for the late reply. I do not use psfrag any more but I just did an experiment. Basically, you have to obtain ps2frag.ps (this one is what I used: ftp://akagi.ms.u-tokyo.ac.jp/pub/TeX/macros/PSfrag/ps2frag.tar.gz), and then use it to generate a pfi file for each eps file, like

    gswin32c -DNODISPLAY -dBATCH -q ps2frag.ps test.eps > test.pfi

    It seems that dviout will not automatically make the pfi files and so this step must be done manually.

  12. Avatarrmcd
    12:05 on November 15th, 2007

    Thank you for posting this! There is no way I would have managed without your guidance here. For some reason dviout could not locate my miktex installation automatically. I found a few changes necessary with MikTeX 2.6 and the use of emacsclientw instead of gnuclientw.

    1. I had to add the following path (in the config dialog)

    TEXFONTS: c:\progra~1\miktex~1.6\\tfm\\

    2. To call emacsclientw from dviout,

    src: d:\progra~1\emacs\bin\emacsclientw.exe^s+%d %s

    3. Within emacs, the customization of tex-output-view-style is (when using the customization editor)

    '(TeX-output-view-style (quote (("^dvi$" "." "dviout -1 %d \"# %n %b\"") ("^pdf$" "." "start \"\" %o") ("^html?$" "." "start \"\" %o"))))

    I mention this because I had some confusion about the “\”" terms in the dviout command. The main point is that the backslashes should *not* appear on the command line when you invoke view. I mention this in case it confuses someone else.

    Finally a question: How do I undo the white text on black background?

  13. Thanks for the inputs and comment. For your final question, please see the explanation of the BMP and scale options of the updated post.

  14. Avatarrmcd
    23:53 on November 17th, 2007

    Thanks a lot for the responses and updates. Your explanation of TEXFONTS was helpful. You’re correct that I have a character that isn’t being generated, which is why I needed that path.

    Regarding emacsclientw, I’m now invoking it with

    src: d:\progra~1\emacs\bin\emacsclientw^s+%d %s -n

    Without the -n switch (no-wait), emacsclient passes control to emacs and then waits for you to finish editing the buffer. If you’re editing and going back and forth between dviout and emacs, you want to use -n.

  15. AvatarBiela
    13:10 on January 7th, 2008

    This all sounds very interessting - really want to get rid of the very slow yap. I am using Miktex 2.7 and tried to follow the described steps. But when I want to open a dvi.file I get the following error message:

    ptmr7t.540(2700)
    Searched C:\Program Files\Miktex2.7\fonts\\dpi540\\dpi540\ptmr7t.pk
    Searched C:\Program Files\Miktex2.7\fonts\\dpi540\\dpi541\ptmr7t.pk
    Searched C:\Program Files\Miktex2.7\fonts\\dpi540\\dpi539\ptmr7t.pk
    Can’t open template file:makepk.exe ^s ^d ^D ^M ljfour

    The makepk.exe file is loacted in C:\Program Files\Miktex2.7\miktex\bin… Does anyone know what I do wrong?

  16. Avatarrmcd
    18:50 on January 16th, 2008

    Biela,

    Let me begin by saying that I’m no expert and I periodically have problems with dviout. It’s very finicky.

    Having said that, make sure that your TEXROOT, TEXPK, and TEXFONTS paths are correct. Whatever you have looks like it is trying to resolve to the wrong directory. The pk font files should (I think) be under c:\documents and settings\… Here are my paths:

    TEXROOT:
    C:\Documents and Settings\All Users\Application Data\MiKTeX\2.7

    TEXPK:
    ^r\fonts\pk\\dpi^d\^s.pk;c:\progra~1\miktex~1.7\fonts\vf\\^s.vf

    TEXFONTS:
    C:\Progra~1\miktex~1.7\fonts\tfm\\

    Good luck!

    Bob

  17. Avatarhhcc
    12:57 on February 5th, 2008

    I have the same problem as Biela: the automatic font creation fails. Have you found the answer?

  18. First, please confirm that the DVI file in question can be rendered in YAP properly.

    Then, to make sure that dviout actually knows about where your makepk.exe is, go into Options->Setup Parameters->Font2. Click on the “gen” button. It will search your harddrive for makepk.exe. (This takes a while.) The search result probably looks like:
    `C:\Progra~1\miktex~1.7\bin\makepk.exe ^s ^d ^D ^M
    Click OK to accept.

    The settings posted by Bob on 2008-01-16 18:50:28 are what a default MiKTeX 2.7 installation would use. You may want to verify them one more time.

    But if the above doesn’t work, then please see my comment on 2007-03-23 10:36:47 and use Yap to figure out where the missing pk font files actually reside (assuming Yap is able to display the dvi file properly). Without that critical information, it would be hard to guess what went wrong.

  19. AvatarFranz
    9:03 on March 4th, 2008

    Hi!
    Thanks for your very good explanation!

    Is there already anything new about the source specials issue with unordered source line numbers in the dvi file?

    I have discovered that this is mainly the problem with modified tex classes. When you use the standard book class, the ordering appears right.

  20. Hi Franz,

    There is nothing new so to speak. Indeed the standard classes probably do not have this problem, but once you venture into more fancy things (especially those that deal with page shipout routines), the problem of having out-of-order source specials seems hard to avoid.

    Having said that, it doesn’t mean we cannot hack dvi previewers like dviout to use a slightly more complicated heuristic that works better most of the time. I have not found the time to do so, however.

  21. AvatarJohn Galt
    13:53 on April 24th, 2008

    Maverick!

    This is a great page and wonderful help. I was able to set up dviout on my Miktex 2.4 installation using your instructions.

    There is only one nagging issue that I would like to resove: In dviout, I can move across pages by pressing Shift+rotating scroll wheel on my mouse or by keeping the wheel pressed and rotating simultaneously. However, I am so used to moving across pages by just rotating the wheel as in YAP that I would like to regain that functionality in dviout.

    Can I do this by changing the key association in property sheets? Any hints or help would be immensely appreciated.

    JG

  22. I understand that what you want is the continuous view from YAP, but I am not sure that this notion is supported in Dviout. It seems to support the single page view only. I believe the mouse support is hardcoded, as described in the help file. Sorry.

  23. Avatarhhcc
    7:22 on April 25th, 2008

    Found the problem: automatic font generation settings were read from the registry. Either unchecking this option (from the REGISTRY property page in the DVIOUT Properties dialog) or including the correct command line in gen (at Font2 property page) solves the problem.

  24. Here is my dviout.par configuraiton file. It seems you must pay attention to the trailing backslashes, occasional reverse-aposthrophe (’`') prefix, and sometimes, double trailing backslashes (?). DVIOUT is an atrocious example of barely usable software.

    That said, here was the PAR file I used to make this work with latest ghostscript 8.62 and MikTex 2.7.

    br=0×800000
    bf=0×800000
    bb=0×1d4c000
    multi=4
    button=+
    dpi=600
    GIF=5
    gsx=C:\Progra~1\GhostScript\gs8.62\bin\gswin32c.exe^-IC:\Progra~1\GhostScript\fonts;C:\Progra~1\GhostScript\gs8.62\lib;C:\Progra~1\GhostScript\gs8.62\Resource^-dTextAlphaBits=4^-dGraphicsAlphaBits=4
    gdat=C:\tmp\dviout_tmp
    gsize=+
    search=448
    sdpi=600
    hyper=0×1d030
    hbuf=0×400000
    ToEdit=^c^V
    FB=2
    varf=+
    gen=”`C:\PROGRA~1\MIKTEX~1.7\miktex\bin\makepk.exe ^s ^d ^D ^M”
    y=F614.295pt:794.96999ptP
    key=DR=-:DM==:JL=x:JF=z
    log=C:\dviout\dviout_tmp
    BMP=6:6:1100
    scale=1:1:-400:2:2:-400:4:4:-400:6:6:1100
    TEXROOT=”C:\Docume~1\AllUse~1\Applic~1\MiKTeX\2.7\”
    TEXPK=^r\fonts\pk\\dpi^d\^s.pk;C:\texmf\fonts\vf\\^s.vf
    TEXFONTS=C:\Progra~1\miktex~1.7\fonts\tfm\\
    src=WinEdt.exe^s”[Open(|%s|);SelPar(%d,8)]”
    gsrc=.eps.pdf=C:\Progra~1\ipe\bin\ipe.exe^s”%s”
    file=c:\dviout\dviout.par

    I still can’t get EPS images to render.

  25. BTW, YAP is slow for me only because of the many graphics I have in the document.

    As a workaround, it’s lightning fast if I just don’t show the graphics, but instead a rectangle bounding box, achieved like this:

    \usepackage[draft]{graphicx}

  26. AvatarKarol
    9:00 on September 14th, 2008

    Hi,

    I see you are able to change shortcuts in dviout, ok what about this: I would like the right mouse button to change the page to the next one (instead of displaying magnifying glass image) and I dont know how to do it.
    Can you help?