diff --git a/CHANGELOG.md b/CHANGELOG.md
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,8 @@
+# lhs2tex-1.24 (2020-05-01)
+
+- Fix line number calculation for LINE pragmas (#81).
+- Fix filepaths in preprocessor mode (#80).
+
 # lhs2tex-1.23 (2020-02-25)
 
 - Compatibility with ghc-8.8 and Cabal-3.0 (#76).
diff --git a/Setup.hs b/Setup.hs
--- a/Setup.hs
+++ b/Setup.hs
@@ -40,7 +40,7 @@
 minPolytableVersion = [0,8,2]
 shortversion = show (numversion `div` 100) ++ "." ++ show (numversion `mod` 100)
 version = shortversion ++ if ispre then "pre" ++ show pre else ""
-numversion = 122
+numversion = 124
 ispre = False
 pre = 1
 
diff --git a/configure b/configure
--- a/configure
+++ b/configure
@@ -1,6 +1,6 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.69 for lhs2tex 1.23.
+# Generated by GNU Autoconf 2.69 for lhs2tex 1.24.
 #
 #
 # Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
@@ -576,8 +576,8 @@
 # Identity of this package.
 PACKAGE_NAME='lhs2tex'
 PACKAGE_TARNAME='lhs2tex'
-PACKAGE_VERSION='1.23'
-PACKAGE_STRING='lhs2tex 1.23'
+PACKAGE_VERSION='1.24'
+PACKAGE_STRING='lhs2tex 1.24'
 PACKAGE_BUGREPORT=''
 PACKAGE_URL=''
 
@@ -636,7 +636,6 @@
 docdir
 oldincludedir
 includedir
-runstatedir
 localstatedir
 sharedstatedir
 sysconfdir
@@ -703,7 +702,6 @@
 sysconfdir='${prefix}/etc'
 sharedstatedir='${prefix}/com'
 localstatedir='${prefix}/var'
-runstatedir='${localstatedir}/run'
 includedir='${prefix}/include'
 oldincludedir='/usr/include'
 docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
@@ -956,15 +954,6 @@
   | -silent | --silent | --silen | --sile | --sil)
     silent=yes ;;
 
-  -runstatedir | --runstatedir | --runstatedi | --runstated \
-  | --runstate | --runstat | --runsta | --runst | --runs \
-  | --run | --ru | --r)
-    ac_prev=runstatedir ;;
-  -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
-  | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
-  | --run=* | --ru=* | --r=*)
-    runstatedir=$ac_optarg ;;
-
   -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
     ac_prev=sbindir ;;
   -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
@@ -1102,7 +1091,7 @@
 for ac_var in	exec_prefix prefix bindir sbindir libexecdir datarootdir \
 		datadir sysconfdir sharedstatedir localstatedir includedir \
 		oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
-		libdir localedir mandir runstatedir
+		libdir localedir mandir
 do
   eval ac_val=\$$ac_var
   # Remove trailing slashes.
@@ -1215,7 +1204,7 @@
   # Omit some internal or obsolete options to make the list less imposing.
   # This message is too long to be a string in the A/UX 3.1 sh.
   cat <<_ACEOF
-\`configure' configures lhs2tex 1.23 to adapt to many kinds of systems.
+\`configure' configures lhs2tex 1.24 to adapt to many kinds of systems.
 
 Usage: $0 [OPTION]... [VAR=VALUE]...
 
@@ -1255,7 +1244,6 @@
   --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
   --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
   --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
-  --runstatedir=DIR       modifiable per-process data [LOCALSTATEDIR/run]
   --libdir=DIR            object code libraries [EPREFIX/lib]
   --includedir=DIR        C header files [PREFIX/include]
   --oldincludedir=DIR     C header files for non-gcc [/usr/include]
@@ -1277,7 +1265,7 @@
 
 if test -n "$ac_init_help"; then
   case $ac_init_help in
-     short | recursive ) echo "Configuration of lhs2tex 1.23:";;
+     short | recursive ) echo "Configuration of lhs2tex 1.24:";;
    esac
   cat <<\_ACEOF
 
@@ -1355,7 +1343,7 @@
 test -n "$ac_init_help" && exit $ac_status
 if $ac_init_version; then
   cat <<\_ACEOF
-lhs2tex configure 1.23
+lhs2tex configure 1.24
 generated by GNU Autoconf 2.69
 
 Copyright (C) 2012 Free Software Foundation, Inc.
@@ -1372,7 +1360,7 @@
 This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
 
-It was created by lhs2tex $as_me 1.23, which was
+It was created by lhs2tex $as_me 1.24, which was
 generated by GNU Autoconf 2.69.  Invocation command line was
 
   $ $0 $@
@@ -1721,9 +1709,9 @@
 
 
 
-VERSION="1.23"
-SHORTVERSION="1.23"
-NUMVERSION=123
+VERSION="1.24"
+SHORTVERSION="1.24"
+NUMVERSION=124
 PRE=1
 
 
@@ -3400,7 +3388,7 @@
 # report actual input values of CONFIG_FILES etc. instead of their
 # values after options handling.
 ac_log="
-This file was extended by lhs2tex $as_me 1.23, which was
+This file was extended by lhs2tex $as_me 1.24, which was
 generated by GNU Autoconf 2.69.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
@@ -3453,7 +3441,7 @@
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
 ac_cs_version="\\
-lhs2tex config.status 1.23
+lhs2tex config.status 1.24
 configured by $0, generated by GNU Autoconf 2.69,
   with options \\"\$ac_cs_config\\"
 
diff --git a/doc/Guide2.pdf b/doc/Guide2.pdf
Binary files a/doc/Guide2.pdf and b/doc/Guide2.pdf differ
diff --git a/lhs2tex.cabal b/lhs2tex.cabal
--- a/lhs2tex.cabal
+++ b/lhs2tex.cabal
@@ -1,6 +1,6 @@
 cabal-version:  >=1.10
 name:           lhs2tex
-version:        1.23
+version:        1.24
 license:        GPL
 license-file:   LICENSE
 author:         Ralf Hinze <ralf.hinze@comlab.ox.ac.uk>, Andres Loeh <lhs2tex@andres-loeh.de>
@@ -24,7 +24,7 @@
   be invoked in another mode to just extract the Haskell code.
 category:       Development, Language
 build-type:     Custom
-tested-with:    GHC == 7.4.2, GHC == 7.6.3, GHC == 7.8.4, GHC == 7.10.3, GHC == 8.0.2, GHC == 8.2.2, GHC == 8.4.4, GHC == 8.6.5, GHC == 8.8.1
+tested-with:    GHC == 7.4.2, GHC == 7.6.3, GHC == 7.8.4, GHC == 7.10.3, GHC == 8.0.2, GHC == 8.2.2, GHC == 8.4.4, GHC == 8.6.5, GHC == 8.8.3, GHC == 8.10.1
 extra-source-files:     AUTHORS
                         CHANGELOG.md
                         INSTALL
diff --git a/src/Main.lhs b/src/Main.lhs
--- a/src/Main.lhs
+++ b/src/Main.lhs
@@ -20,6 +20,7 @@
 > import Control.Monad
 > import Control.Monad.Except
 > import Control.Monad.State ( MonadState(..), modify )
+> import Data.Maybe (fromMaybe)
 > import Prelude hiding ( getContents, pi )
 >
 > import qualified Version as V
@@ -106,19 +107,24 @@
 >                               -- |++ [ (s, Bool False) || s <- ["underlineKeywords", "spacePreserving", "meta", "array", "latex209", "times", "euler" ] ]|
 
 > preprocess                    :: State -> [Class] -> Bool -> [String] -> IO ()
+
+f1 is the argument to -h
+f2 is the input file
+f3 is the output file
+
 > preprocess flags dirs lit (f1:f2:f3:_)
 >                               =  if (f1 == f2) && not lit
 >                                  then copyFile f2 f3
->                                  else do c <- readFile f1
+>                                  else do c <- readFile f2
 >                                          case matchRegex (mkRegexWithOpts "^%include" True False) c of
 >                                            Nothing -> if lit then
 >                                                          do h <- openOutputFile f3
->                                                             lhs2TeX NewCode (flags { output = h }) (Directive Include "lhs2TeX.fmt" : dirs) [f1]
+>                                                             lhs2TeX NewCode (flags { output = h, linefile = Just f1 }) (Directive Include "lhs2TeX.fmt" : dirs) [f2]
 >                                                             hClose h
 >                                                       else copyFile f2 f3
 >                                            Just _  -> -- supposed to be an lhs2TeX file
 >                                                       do h <- openOutputFile f3
->                                                          lhs2TeX NewCode (flags { output = h }) dirs [f1]
+>                                                          lhs2TeX NewCode (flags { output = h, linefile = Just f1 }) dirs [f2]
 >                                                          hClose h
 > preprocess _ _ _ _            =  error "preprocess: too few arguments"
 
@@ -423,7 +429,9 @@
 >         select Poly st        =  do (d, pstack') <- Poly.display (lang st) (lineno st + 1) (fmts st) (isTrue (toggles st) auto) (separation st) (latency st) (pstack st) s
 >                                     return (d, st{pstack = pstack'})
 >         select NewCode st     =  do d <- NewCode.display (lang st) (fmts st) s
->                                     let p = sub'pragma $ Text ("LINE " ++ show (lineno st + 1) ++ " " ++ show (takeFileName $ file st))
+>                                     -- display trims the contents, so for the line number in the pragma to be correct, we have to check initial newlines
+>                                     let nlOffset = newlines (takeWhile isSpace s)
+>                                     let p = sub'pragma $ Text ("LINE " ++ show (lineno st + nlOffset) ++ " " ++ show (fromMaybe (takeFileName $ file st) (linefile st)))
 >                                     return ((if pragmas st then ((p <<>> sub'nl) <<>>) else id) d, st)
 >         select Markdown st    =  do d <- NewCode.display (lang st) (fmts st) s
 >                                     return (d, st)
diff --git a/src/State.lhs b/src/State.lhs
--- a/src/State.lhs
+++ b/src/State.lhs
@@ -19,6 +19,7 @@
 >                                          lang       :: Lang,          -- Haskell or Agda, currently
 >                                          verbose    :: Bool,
 >                                          searchpath :: [FilePath],
+>                                          linefile   :: Maybe FilePath,  -- The filepath to use for LINE pragmas, passed by the -h option by GHC in preprocessor mode
 >                                          file       :: FilePath,      -- also used for `hugs'
 >                                          lineno     :: LineNo,
 >                                          ofile      :: FilePath,
@@ -70,6 +71,7 @@
 >                                          separation = 2,
 >                                          latency    = 2,
 >                                          pstack     = [],
+>                                          linefile   = Nothing,
 >                                          -- ks, 03.01.04: added to prevent warnings during compilation
 >                                          style      = error "uninitialized style",
 >                                          file       = error "uninitialized filename",
diff --git a/src/TeXParser.lhs b/src/TeXParser.lhs
--- a/src/TeXParser.lhs
+++ b/src/TeXParser.lhs
@@ -4,7 +4,7 @@
 
 %if codeOnly || showModuleHeader
 
-> module TeXParser              (  texparse  )
+> module TeXParser              (  texparse, newlines  )
 > where
 > import Data.Char              (  isSpace, isAlpha  )
 > import TeXCommands
@@ -219,7 +219,7 @@
 >     Many s <<| (Many s' : ts) =  Many (s ++ s') : ts
 >     t <<| ts                  =  t : ts
 
-\NB The first two equations make |compress| incrementel (?); otherwise
+\NB The first two equations make |compress| incremental; otherwise
 \[
     |do s <- readFile "Examples/InfI.lhs"; mapM_ print (compress (map One s))|
 \]
