John Pye wrote: > Hi all > > I know that this has 'been done' but I'm not sure how to go about it > myself. I would like to link to an external source code file and 'pull > it in' to my compiled document when I use pdflatex. I would like to > apply source code highlighting, although that's not essential (the > language I'm using is not one that is supported by any of the tools). > > I worked out how to import external code, but not how to maintain a > link. Do I need to use ERT? Can LyX be set to use 'highlight' on-the-fly > as for graphics formats, or must I prepare the latex by hand?
Hi John, I strongly recommend the listings package for this purpose, which provides excellent means to print and format listings, highlight your own identifiers, refer to line number etc. And it comes with a very good documentation. You need to do that in ERT, though. However, this is very simple. Take a look at the attached example. Daniel
listings.lyx
Description: application/lyx
#ifndef __ObserverPattern_ah__
#define __ObserverPattern_ah__
#include <set>
#include <map>
using namespace std;
aspect ObserverPattern {
public:
// interfaces for each role
struct ISubject {};
struct IObserver {
virtual void update (ISubject *) = 0;
};
// to be defined by the concrete derived aspect
pointcut virtual observers() = 0;
([EMAIL
PROTECTED]:[EMAIL PROTECTED])
pointcut virtual subjects() = 0;
// defaults to any non-const member of subjects()
pointcut virtual subjectChange() =
execution( "% ...::%(...)" && !"% ...::%(...) const" ) && within(
subjects() );
advice observers () : slice class : public ObserverPattern::IObserver;
advice subjects () : slice class : public ObserverPattern::ISubject;
advice subjectChange() : after () {
ISubject* subject = tjp->that ();
updateObservers (subject);
}
([EMAIL PROTECTED]:[EMAIL PROTECTED])
virtual void addObserver (ISubject *subject, IObserver *observer) {
SubjectMap::iterator subject_pos = _perSubjectObservers.find (subject);
if (subject_pos != _perSubjectObservers.end ()) {
ObserverSet &oset = (*subject_pos).second;
oset.insert (observer);
}
else {
ObserverSet oset;
oset.insert (observer);
_perSubjectObservers.insert (SubjectMapPair (subject, oset));
}
}
virtual void updateObservers (ISubject* subject) {
SubjectMap::iterator subject_pos = _perSubjectObservers.find (subject);
if (subject_pos != _perSubjectObservers.end ()) {
ObserverSet &oset = (*subject_pos).second;
for (ObserverSet::iterator iter = oset.begin (); iter != oset.end ();
++iter)
(*iter)->update(subject);
}
}
private:
// data structures to manage subjects and observers
typedef set<IObserver*> ObserverSet;
typedef map<ISubject*,ObserverSet> SubjectMap;
typedef SubjectMap::value_type SubjectMapPair;
SubjectMap _perSubjectObservers;
};
#endif // __ObserverPattern_ah__
