+.
+\end_layout
+
+\begin_layout Standard
+Another useful tool is command-line based client you will find in
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+src/client/lyxclient
+\end_layout
+
+\end_inset
+
+.
+\end_layout
+
+\begin_layout Section
+Normal communication
+\end_layout
+
+\begin_layout Standard
+To issue a LyX call, the client writes a line of ASCII text into the input
+ pipe.
+ This line has the following format:
+\end_layout
+
+\begin_layout Quote
+LYXCMD:
+\emph on
+clientname
+\emph default
+:
+\emph on
+function
+\emph default
+:
+\emph on
+argument
+\end_layout
+
+\begin_layout Description
+clientname is a name that the client can choose arbitrarily.
+ Its only use is that LyX will echo it if it sends an answer—so a client
+ can dispatch results from different requesters.
+\end_layout
+
+\begin_layout Description
+function is the function you want LyX to perform.
+ It is the same as the commands you'd use in the minibuffer.
+\end_layout
+
+\begin_layout Description
+argument is an optional argument which is meaningful only to some functions
+ (for instance, the
+\begin_inset Quotes eld
+\end_inset
+
+self-insert
+\begin_inset Quotes erd
+\end_inset
+
+ LFUN will insert the argument as text at the cursor position).
+\end_layout
+
+\begin_layout Standard
+The answer from LyX will arrive in the output pipe and be of the form
+\end_layout
+
+\begin_layout Quote
+INFO:
+\emph on
+clientname
+\emph default
+:
+\emph on
+function
+\emph default
+:
+\emph on
+data
+\end_layout
+
+\begin_layout Standard
+where
+\emph on
+clientname
+\emph default
+ and
+\emph on
+function
+\emph default
+ are just echoed from the command request, while
+\emph on
+data
+\emph default
+ is more or less useful information filled according to how the command
+ execution worked out.
+ Some commands, such as
+\begin_inset Quotes eld
+\end_inset
+
+font-state
+\begin_inset Quotes erd
+\end_inset
+
+, will return information about the internal state of LyX, while other will
+ return an empty data-response.
+ This means that the command execution went fine.
+\end_layout
+
+\begin_layout Standard
+In case of errors, the response from LyX will have this form
+\end_layout
+
+\begin_layout Quote
+ERROR:
+\emph on
+clientname
+\emph default
+:
+\emph on
+function
+\emph default
+:
+\emph on
+error message
+\end_layout
+
+\begin_layout Standard
+where the
+\emph on
+error message
+\emph default
+ should contain an explanation of why the command failed.
+\end_layout
+
+\begin_layout Standard
+Examples:
+\end_layout
+
+\begin_layout LyX-Code
+echo "LYXCMD:test:beginning-of-buffer:" >~/.lyxpipe.in
+\begin_inset Newline newline
+\end_inset
+
+echo "LYXCMD:test:get-xy:" >~/.lyxpipe.in
+\begin_inset Newline newline
+\end_inset
+
+read a <~/.lyxpipe.out
+\begin_inset Newline newline
+\end_inset
+
+echo $a
+\end_layout
+
+\begin_layout Section
+Notification
+\end_layout
+
+\begin_layout Standard
+LyX can notify clients of events going on asynchronously.
+ Currently it will only do this if the user binds a key sequence with the
+ function
+\begin_inset Quotes eld
+\end_inset
+
+notify
+\begin_inset Quotes erd
+\end_inset
+
+.
+ The format of the string LyX sends is as follows:
+\end_layout
+
+\begin_layout Quote
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+NOTIFY:
+\end_layout
+
+\end_inset
+
+
+\emph on
+key-sequence
+\end_layout
+
+\begin_layout Standard
+where
+\emph on
+key-sequence
+\emph default
+ is the printed representation of the key sequence that was actually typed
+ by the user.
+\end_layout
+
+\begin_layout Standard
+This mechanism can be used to extend LyX's command set and implement macros.
+ Bind some key sequence to
+\begin_inset Quotes eld
+\end_inset
+
+notify
+\begin_inset Quotes erd
+\end_inset
+
+.
+ Then start a client that listens on the output pipe, dispatches the command
+ according to the sequence, and starts a function that may use LyX calls
+ and LyX requests to issue a command or a series of commands to LyX.
+\end_layout
+
+\begin_layout Section
+The simple LyX Server Protocol
+\end_layout
+
+\begin_layout Standard
+LyX implements a simple protocol that can be used for session management.
+ All messages are of the form
+\end_layout
+
+\begin_layout Quote
+LYXSRV:
+\emph on
+clientname
+\emph default
+:
+\emph on
+protocol message
+\end_layout
+
+\begin_layout Standard
+where
+\emph on
+protocol message
+\emph default
+ can be
+\begin_inset Quotes eld
+\end_inset
+
+hello
+\begin_inset Quotes erd
+\end_inset
+
+ or
+\begin_inset Quotes eld
+\end_inset
+
+bye
+\begin_inset Quotes erd
+\end_inset
+
+.
+ If
+\begin_inset Quotes eld
+\end_inset
+
+hello
+\begin_inset Quotes erd
+\end_inset
+
+ is received from a client, LyX will report back to inform the client that
+ it's listening to it's messages, while
+\begin_inset Quotes eld
+\end_inset
+
+bye
+\begin_inset Quotes erd
+\end_inset
+
+ sent from LyX will inform clients that LyX is closing.
+\end_layout
+
+\begin_layout Section
+Reverse DVI/PDF search
+\end_layout
+
+\begin_layout Standard
+Some DVI/PDF viewers
+\begin_inset Foot
+status collapsed
+
+\begin_layout Plain Layout
+The following viewers offer the reverse PDF search feature: Okular on KDE/Linux,
+ Skim on Mac OSX and SumatraPDF on Windows.
+\end_layout
+
+\end_inset
+
+ provide
+\emph on
+reverse search
+\emph default
+ facility (also called
+\emph on
+inverse search
+\emph default
+).
+ This means that you can tell LyX to put the cursor to a specific line in
+ the document by clicking at the respective position in the DVI/PDF output.
+ To achieve this, the viewer must be able to communicate with LyX.
+ This is done via the LyX server either by using the named pipe (
+\emph on
+lyxpipe
+\emph default
+), or the UNIX domain socket (
+\emph on
+lyxsocket
+\emph default
+) that LyX creates in its temporary directory (this is the way the
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+lyxclient
+\end_layout
+
+\end_inset
+
+ program communicates with LyX).
+ In some cases, you need a helper script that mediates between the viewer
+ and LyX, in others, the viewer can communicate with LyX directly.
+ This depends on the selected viewer and on your operating system.
+ The same applies to the way viewers need to be configured and the way the
+ reverse search is actually performed.
+ In what follows, we will thus describe how to setup reverse search for
+ specific viewers.
+ Before we turn to this, though, we will explain what needs to be done generally
+ to enable reverse search in the DVI/PDF output.
+\end_layout
+
+\begin_layout Subsection
+\begin_inset CommandInset label
+LatexCommand label
+name "sub:rev-search"
+
+\end_inset
+
+Automatic setup
+\end_layout
+
+\begin_layout Standard
+In most cases LyX will do the work for you by enabling
+\begin_inset Flex MenuItem
+status collapsed
+
+\begin_layout Plain Layout
+Document\SpecialChar \menuseparator
+Output\SpecialChar \menuseparator
+Synchronize with Output
+\end_layout
+
+\end_inset
+
+.
+ In such a case LyX will automatically insert the necessary SyncTeX macro
+ (for PDF) or load the srcltx package (for DVI) respectively.
+ This option can be easily reached also on
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+View/Update
+\end_layout
+
+\end_inset
+
+ Toolbar.
+\end_layout
+
+\begin_layout Standard
+If you need a different setting, you can select or input a custom macro
+ from the drop down box just below
+\begin_inset Flex MenuItem
+status collapsed
+
+\begin_layout Plain Layout
+Document\SpecialChar \menuseparator
+Output\SpecialChar \menuseparator
+Synchronize with Output
+\end_layout
+
+\end_inset
+
+.
+\end_layout
+
+\begin_layout Standard
+Please note that including the
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+srcltx
+\end_layout
+
+\end_inset
+
+ package or
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+src-specials
+\end_layout
+
+\end_inset
+
+ sometimes has an undesired impact on the typesetting.
+ Thus, you should switch output synchronization off for the final typesetting
+ if you use the
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+srcltx
+\end_layout
+
+\end_inset
+
+ package or
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+src-specials
+\end_layout
+
+\end_inset
+
+.
+\end_layout
+
+\begin_layout Standard
+In case you need some more special settings that are not covered by the
+ automatic settings, read the next section about how to set up output synchroniz
+ation manually.
+ If the automatic setup suits your needs, you can readily jump to section
+\begin_inset space ~
+\end_inset
+
+
+\begin_inset CommandInset ref
+LatexCommand ref
+reference "sub:configuring-viewers"
+
+\end_inset
+
+, where the necessary configuration steps in your viewer -- needed both
+ with the automatic and the manual setup -- are described.
+\end_layout
+
+\begin_layout Subsection
+Manual setup
+\end_layout
+
+\begin_layout Standard
+LaTeX provides several different methods for reverse search.
+ Some are built-in in the
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+latex/pdflatex
+\end_layout
+
+\end_inset
+
+ program, some are provided by external packages.
+ Your choice depends on whether your LaTeX distribution already provides
+ a given method (the built-in methods are rather new) and whether your viewer
+ can cope with it.
+ The available methods are described in the following.
+\end_layout
+
+\begin_layout Subsubsection*
+Built-in DVI-search via src-specials (DVI only)
+\end_layout
+
+\begin_layout Standard
+This method provides the DVI file with the necessary information for reverse
+ search.
+ It is available in LaTeX since quite some time (any somewhat recent LaTeX
+ distribution should include it), and it works reliably.
+ To enable it, change the
+\begin_inset Flex MenuItem
+status collapsed
+
+\begin_layout Plain Layout
+LaT
+\begin_inset ERT
+status collapsed
+
+\begin_layout Plain Layout
+
+{}
+\end_layout
+
+\end_inset
+
+eX (plain)->DVI
+\end_layout
+
+\end_inset
+
+ or
+\begin_inset Flex MenuItem
+status collapsed
+
+\begin_layout Plain Layout
+LaT
+\begin_inset ERT
+status collapsed
+
+\begin_layout Plain Layout
+
+{}
+\end_layout
+
+\end_inset
+
+eX (plain)->DraftDVI
+\end_layout
+
+\end_inset
+
+ converter in
+\begin_inset Flex MenuItem
+status collapsed
+
+\begin_layout Plain Layout
+Preferences\SpecialChar \menuseparator
+File Handling\SpecialChar \menuseparator
+Converters
+\end_layout
+
+\end_inset
+
+ to
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+latex -src-specials $$i
+\end_layout
+
+\end_inset
+
+.
+ If this doesn't work, check if your TeX engine needs different options
+ (the syntax might differ in some distributions).
+\end_layout
+
+\begin_layout Subsubsection*
+External Packages (PDFSync and scrltx)
+\end_layout
+
+\begin_layout Standard
+The packages
+\emph on
+pdfsync
+\emph default
+ and
+\emph on
+scrltx
+\emph default
+ provide reverse search facility for PDF output (via pdflatex) and DVI output,
+ respectively.
+ In order to enable it, load the packages in the LyX preamble:
+\end_layout
+
+\begin_layout Itemize
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\backslash
+usepackage{pdfsync}
+\end_layout
+
+\end_inset
+
+ for reverse PDF search,
+\end_layout
+
+\begin_layout Itemize
+
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\backslash
+usepackage[active]{srcltx}
+\end_layout
+
+\end_inset
+
+ for reverse DVI search.
+\end_layout
+
+\begin_layout Standard
+If you want to be able to perform both DVI and PDF reverse searches, you
+ can also insert in the preamble the following lines
+\end_layout
+
+\begin_layout LyX-Code
+
+\backslash
+usepackage{ifpdf}
+\begin_inset Newline newline
+\end_inset
+
+
+\backslash
+ifpdf
+\begin_inset Newline newline
+\end_inset
+
+
+\backslash
+usepackage{pdfsync}
+\begin_inset Newline newline
+\end_inset
+
+
+\backslash
+else
+\begin_inset Newline newline
+\end_inset
+
+
+\backslash
+usepackage[active]{srcltx}
+\begin_inset Newline newline
+\end_inset
+
+
+\backslash
+fi
+\end_layout
+
+\begin_layout Standard
+This way, you can preview the file as either DVI or PDF (pdflatex) and the
+ right package will be used.
+\end_layout
+
+\begin_layout Standard
+Note that PDFSync might affect the output layout of your document.
+ It is therefore advised to disable PDFsync for final documents.
+\end_layout
+
+\begin_layout Subsubsection*
+Built-in reverse search via SyncTeX (DVI and PDF)
+\end_layout
+
+\begin_layout Standard
+Recent versions of
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+(pdf)latex
+\end_layout
+
+\end_inset
+
+ have built-in support for both PDF and DVI reverse search.