A macro with @ in its name must be used after \makeatletter
\\pagecolor{lyxbg}
\\usepackage[%s,tightpage]{preview}
\\usepackage{ifthen}
-\\ifthenelse{\equal{\f@family}{cmr}}{
-\\IfFileExists{lmodern.sty}{\\usepackage{lmodern}}{\\usepackage{ae,aecompl}}}{}
\\makeatletter
+\\ifthenelse{\\equal{\\f@family}{cmr}}{
+\\IfFileExists{lmodern.sty}{\\usepackage{lmodern}}{\\usepackage{ae,aecompl}}}{}
\\g@addto@macro\\preview{\\begingroup\\color{lyxbg}\\special{ps::clippath fill}\\color{lyxfg}}
\\g@addto@macro\\endpreview{\\endgroup}
\\makeatother