Edit
Links
This page describes how to use LyX under Cygwin on Windows by building Qt/Win and LyX from source using Cygwin tools. If you don't want or need to compile LyX yourself, you can download an archive from the binary distribution site ftp://ftp.lyx.org/pub/lyx/bin/, un-tar it (using the cygwin tar, not native tools), and follow the instructions. Note that official Cygwin packages for the various Qt4 libraries are available in the Cygwin distribution for the X11 backend, so, if you want a Qt4/X11 version, you can simply install one or more of those. Instead, if you want a cygwin version of Qt4 but using the native Windows graphics backend, you can continue reading.
Please note that the procedure outlined here applies to Qt 4.8.6 only. It cannot be used with a different version, unless you adapt the provided patches. Also note that this Qt4 port has mainly been tested with LyX but it is believed to be a fairly complete port.
We need quite a slew of tools to build Qt and LyX. Be sure to install at least the cygwin packages listed below. Due to a dependency mechanism, all other tools not listed here should also be marked for installation (I hope I forgot nothing).
Instead of using the setup program, if you've installed wget you can install everything from the command line using the apt-cyg script:
wget https://raw.githubusercontent.com/transcode-open/apt-cyg/master/apt-cyg install apt-cyg /usr/local/bin apt-cyg install bc bison cygport file-devel gcc-g++ gettext-devel \ libaspell-devel libbz2-devel libdbus1-devel libexpat1-devel \ libiodbc-devel libjpeg-devel libturbojpeg-devel libmng-devel \ libmysqlclient-devel libpng-devel libpcre-devel libpq5 libpq-devel \ libsqlite3-devel libsybdb-devel libtiff-devel libxml2-devel m4 \ make openssl-devel patch pkg-config python
We will be using cygport to build all packages. For not cluttering the main
tree, we will be installing things into /usr/local. Unfortunately, cygport is
thought for building official Cygwin packages that install into /usr. Thus,
we need to apply a small patch. Download cygport.diff and
apply it as follows:
cd /usr/share/cygport/lib wget http://www.lyx.org/images/svnwiki/cygwin/cygport.diff patch -p0 < cygport.diff
LyX uses the Qt4 QProcess class for launching external programs. The Qt4 implementantion of QProcess uses the fork call, which is quite expensive on Cygwin. We will be patching Qt4 such that QProcess will use an efficient and POSIX-compliant user-mode implementation of posix_spawn that improves process-creation performance considerably. Thus, before building the Qt4 libraries, we need to compile and install cygspawn. Download the archive cygspawn.tar.gz and unpack it in /usr/local/src:
mkdir /usr/local/src cd /usr/local/src wget http://www.lyx.org/images/svnwiki/cygwin/cygspawn.tar.gz tar xvf cygspawn.tar.gz
Now build the cygspawn and cygspawn-devel packages by issuing the
following commands:
cd /usr/local/src/cygspawn cygport cygspawn.cygport download # download the source from github cygport cygspawn.cygport all # apply patches and make the cygwin packages
You should now find the cygspawn and cygspawn-devel packages in
<workdir>/dist/cygspawn, where <workdir> is the work directory
created by cygport, which is typically named as packagename-version.arch.
Here, packagename and version are obvious, while arch is i686
for 32-bit, but x86_64 for 64-bit cygwin. Thus, if you are using 32-bit
cygwin, the packages will be in cygspawn-1.0.0-3.i686/dist/cygspawn,
otherwise you will find them in cygspawn-1.0.0-3.x86_64/dist/cygspawn.
These packages could be installed by simply unpacking their archives from
the root directory, but it is more convenient installing them through the
cygwin installation tool (either setup-x86.exe or setup-x86_64.exe).
This means that we need creating a local repository for cygwin packages.
Suppose that we choose /setup/local as the directory of this local
repository. If you are using 32-bit cygwin, create the directories
mkdir -p /setup/local/x86/dist
otherwise, if you are using 64-bit cygwin, create the directories
mkdir -p /setup/local/x86_64/dist
and then copy there the whole tree under <workdir>/dist/cygspawn, i.e.,
cp -r <workdir>/dist/cygspawn /setup/local/<arch>/dist
where you have to replace <workdir> and <arch> according to the
architecture of your cygwin installation (32- or 64-bit).
We now need creating an index that will be used by the setup program.
Download the genini script in /usr/local/bin,
make it executable and then launch it as follows (replace <arch>
with x86 for 32-bit or with x86_64 for 64-bit):
cd /usr/local/bin wget http://www.lyx.org/images/svnwiki/cygwin/genini chmod a+rx genini cd /setup/local genini --recursive --release=local --output=<arch>/setup.ini <arch>
This will create the index file <arch>/setup.ini and we are now ready to
launch the cygwin setup installation tool. After doing that, choose
"Install from Local Directory", leave the "Root Directory" pointing to
your cygwin installation, and then choose as "Local Package Directory"
the local repository /setup/local (as the setup tool is a native
program, this directory has to be specified in Windows form, probably
as C:\cygwin\setup\local). You should now be able to select the
cygspawn and cygspawn-devel packages for installation. After installing
them, let us remove the work directory created by cygport, as it is not
necessary anymore:
cd /usr/local/src/cygspawn cygport cygspawn.cygport finish
LyX can use either aspell or hunspell as a spell checker. The
aspell package is provided as an official Cygwin package but its
selection of dictionaries is limited. Instead, dictionaries and thesauri files
for hunspell are provided on the LyX website for a wide range of languages.
Unfortunately, hunspell is not provided as an official Cygwin package.
It could be installed from the
cygwinports
site, but it is also easily built from source. Download the archive
hunspell.tar.gz and unpack
it in /usr/local/src:
cd /usr/local/src wget http://www.lyx.org/images/svnwiki/cygwin/hunspell.tar.gz tar xvf hunspell.tar.gz
Now build the hunspell packages by issuing the following commands:
cd /usr/local/src/hunspell cygport hunspell.cygport download # download the source from sourceforge cygport hunspell.cygport all # apply patches and make the cygwin packages
Copy the whole tree under <workdir>/dist/hunspell to the local repository
(again, replace <workdir> and <arch> as appropriate) and then cleanup the
work directory:
cp -r <workdir>/dist/hunspell /setup/local/<arch>/dist cygport hunspell.cygport finish
Afterwards, update the index for the setup installation tool
cd /setup/local genini --recursive --release=local --output=<arch>/setup.ini <arch>
before launching it to install the libhunspell-devel package (this will
also pull in the hunspell library).
We can now proceed to build the Qt4 libraries.
The Qt4 libraries we are going to build use the native Windows graphics backend,
not X11. Until some time ago, the official Cygwin repositories offered an
opengl package to develop portable OpenGL programs that did not require an
X server to run. This package was later declared obsoleted when OpenGL support
was added to the Cygwin X server. However, we need this package for building
a fully functional Qt4 port not relying on X11. So, download the
opengl.tar.gz archive and unpack it in
/setup/local/<arch>/dist (replace <arch> with x86 or x86_64,
as appropriate):
cd /usr/local/src wget http://www.lyx.org/images/svnwiki/cygwin/opengl.tar.gz cd /setup/local/<arch>/dist tar xvf /usr/local/src/opengl.tar.gz
Then, run again the genini script
cd /setup/local genini --recursive --release=local --output=<arch>/setup.ini <arch>
and install the opengl package through the setup program by using
again /setup/local as the "Local Package Directory".
We are now ready to build the Qt4 libraries.
cd /usr/local/src wget http://www.lyx.org/images/svnwiki/cygwin/qt4win.tar.gz tar xvf qt4win.tar.gz
cd /usr/local/src/qt cygport qt4win.cygport download # download the source from qt-project.org cygport qt4win.cygport all # apply patches and make the cygwin packages
<workdir>/dist/qt4win to the local repository (where, again, you have
to replace <workdir> and <arch> according to the architecture of
your cygwin installation):
cp -r <workdir>/dist/qt4win /setup/local/<arch>/dist
cd /setup/local genini --recursive --release=local --output=<arch>/setup.ini <arch>
libqt4-core-devel and libqt4-gui-devel packages and their
dependencies (which are automatically pulled in).
After removing the work directory used for building the Qt4 libraries:
cd /usr/local/src/qt cygport qt4win.cygport finish
we can move to building LyX.
cd /usr/local/src wget http://www.lyx.org/images/svnwiki/cygwin/lyxwin.tar.gz tar xvf lyxwin.tar.gz
cd /usr/local/src/lyxwin sed -i -e 's/VERSION=.*/VERSION=2.1.X/' lyxwin.cygport
sed -i -e 's/running.patch/running.patch\n\t64bit.patch/' lyxwin.cygport
cygport lyxwin.cygport download cygport lyxwin.cygport all
cp -r <workdir>/dist/LyXwin /setup/local/<arch>/dist cygport lyxwin.cygport finish
cd /setup/local genini --recursive --release=local --output=<arch>/setup.ini <arch>
LyXwin
package.
/usr/local/share/dict/ and /usr/local/share/thes/ directories,
respectively. However, these locations can be configured in the preferences.
The reverse search feature (also called inverse search) allows the cursor in LyX to automatically jump to the point corresponding to a given position in the DVI or PDF file being previewed. When a reverse search is started (xdvi uses ctrl-click, whereas yap and SumatraPDF use double click), the viewer calls an external program or script with two arguments, a filename and a line number. The called program should pass this info to a running instance of LyX. This can be done through the LyX server either by using a named pipe (lyxpipe), or the unix domain socket (lyxsocket) that lyx creates in its temporary directory (this is the way the lyxclient program communicates with LyX).
The reverse search feature can be enabled in LyX as follows:
LaTeX (plain)->DVI or
LaTeX (plain)->DraftDVI converter in
Tools->Preferences->File Handling->Converters to
latex -src-specials $$i. As an alternative to redefining the
converter, insert \usepackage[active]{srcltx} in the preamble
of the LyX file.
LaTeX (pdflatex)->PDF (pdflatex)
converter in Tools->Preferences->File Handling->Converters to
pdflatex --synctex=-1 $$i. As an alternative to redefining the
converter, insert \usepackage{pdfsync} in the preamble.
Note that only SumatraPDF supports reverse PDF search, currently.
In order to allow both DVI and PDF reverse search, you can also insert
in the preamble the following lines:
\usepackage{ifpdf}
\ifpdf
\usepackage{pdfsync}
\else
\usepackage[active]{srcltx}
\fi
Tools->Preferences->File Handling->File formats to
xdvi -editor 'lyxeditor %f %l', and be sure to specify the
LyXServer pipe path in Tools->Preferences->Paths (a good choice is
$HOME/.lyx/lyxpipe). You should find the lyxeditor.exe program in
/usr/local/bin, as it is installed by default on Cygwin.
-g %f %l.
In this way you will be using the lyxsocket for communicating with LyX.
If, for whatever reason, you want to use the lyxpipe, omit -g, and be sure
to specify the LyXServer pipe path in the LyX preferences.
SumatraPDF -inverse-search "lyxeditor -g %f %l" in
the viewer setting in
Tools->Preferences->File Handling->File formats->PDF (pdflatex).
The -g enables communication via the lyxsocket (recommended); omit the
-g option if you want to use the lyxpipe, and be sure to specify the
LyXServer pipe path in the LyX preferences.
If you did no mistakes, and if src-specials are activated as previously described, whenever you ctrl-click in xdvi, or double click in yap or SumatraPDF, the cursor in LyX should jump to the desired location.
The forward search feature allows you to let a dvi/pdf viewer jump (near) to a
position corresponding to the cursor position in LyX. Forward search is enabled
in the same way as reverse search is (see the previous section) but you also
need to specify in the preferences a proper command for the used viewer.
If you use one of the already supported viewers, you can do this by selecting
one of the predefined commands in Tools->Preferences->Output->General.
There, you will find the commands to be used with xdvi, yap, and SumatraPDF
(if you don't have SumatraPDF 1.9 or a later version, you need the external
command CMCDDE, downloadable from ftp://ftp2.commence.com/pub/freebies/).
If you use a different viewer, you will have to check whether it supports
forward search and manually enter the required command in
Tools->Preferences->Output->General.
After positioning the cursor in LyX, a forward search is initiated by either
the Navigate->Forward search main menu entry or the Forward search
context menu entry.
If you use the cygwin texlive package, you will notice that forward search
doesn't seem to work with SumatraPDF. Indeed, SumatraPDF is a native Windows
program and thus it does not understand the posix paths that texlive inserts
in the produced synctex file. However, the synctex file is a simple text file
and thus can be easily modified with the sed program. In this case, you can
use the following script as your pdf viewer. Give it the name SumatraPDF.sh,
make it executable and place it in the PATH, for example, in /usr/local/bin.
Then enter SumatraPDF.sh in the viewer setting in
Tools->Preferences->File Handling->File formats->PDF (pdflatex).
The script simply converts all paths in the synctex file to the Windows
format before calling the real SumatraPDF program. It also takes care of the
reverse search setting.
#!/bin/bash
pdfname=$(basename "1ドル")
stem=$(basename "1ドル" .pdf)
compressed=no
cd $(dirname "1ドル")
if [ -f "$stem.synctex.gz" ]; then
compressed=yes
gunzip "$stem.synctex.gz"
fi
if [ -f "$stem.synctex" ]; then
sed -i -e '/^Input:/{h;s,^Input:.*:\(.*\),ドルcygpath -m "1円",e;x;
s,:\(.*\):.*,ドル:1円:,;G;s,\n,,;}' "$stem.synctex"
if [ "$compressed" = "yes" ]; then
gzip "$stem.synctex"
fi
fi
SumatraPDF -inverse-search "lyxeditor -g %f %l" "$pdfname"