LyXCross-Reference generic Text

Information and discussion about LyX, a WYSIWYM editor, available for Linux, Windows and Mac OS X systems.
Post Reply
ss4johnny
Posts: 3
Joined: Mon Dec 19, 2011 6:00 pm

Cross-Reference generic Text

Post by ss4johnny »

I recently started using LyX for some articles that I'm writing. I think I have a pretty decent handle on the basic functions after 10+ hours. Anyway, I was thinking that one thing that crops up a lot is that I might say something like:
U.S. GDP growth is expected to be 10%.
And then I refer to the 10% again multiple times throughout a document
I tried to use LyX to create a label like [U.S.-GDP-growth] and then cross-reference to [Ref: U.S.-GDP-growth]. But it doesn't produce the text 10% in other sentences. It's just blank.

I take this to mean that you can't label or cross-reference to some generic text. Is my understanding correct? It seems like a simple thing to change.

More generally, I may want to create a master document with individual words. numbers, phrases, sentences, whole paragraphs, parts of equations, or whole equations that are meant to be repeated in key places. Rather than update them multiple times throughout the document, I would rather do them in one place and then refer to them many times throughout the document.

Presuming I didn't pass up some amazing feature, anyone know how to pass this along to developers?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Stefan Kottwitz
Site Admin
Posts: 10348
Joined: Mon Mar 10, 2008 9:44 pm

Cross-Reference generic Text

Post by Stefan Kottwitz »

Hi,

welcome to the board!

Simply define macros in your preamble, or in a file such as macros.tex and load it within your LyX document preamble by

Code: Select all

\input{macros}
Your macro.tex could look like:

Code: Select all

\newcommand*{\USGDPgrowth}{10\%}
\newcommand*{\phrase}{A long phrase}
...
Stefan
LaTeX.org admin
ss4johnny
Posts: 3
Joined: Mon Dec 19, 2011 6:00 pm

Re: Cross-Reference generic Text

Post by ss4johnny »

Thanks!. I will try this (I had not quite gotten to doing macros in Lyx). It looks like it will be useful.

Edit: I tried it and was having some difficulties. I exported the a LyX file with the commands to a .tex file. In the second file, I inserted that macros code as TeX, which seemed to work, but couldn't seem to figure out how to get the references to show up.
ss4johnny
Posts: 3
Joined: Mon Dec 19, 2011 6:00 pm

Re: Cross-Reference generic Text

Post by ss4johnny »

I realized what wasn't work when I first was trying this. I was creating a .tex file by typing that text in LyX and exporting to a LaTeX(plain) format. Instead, I just created a .txt file copied that text in and saved it as .tex. Apparently the LyX exported was adding some code that prevented it from compiling.
Post Reply