2

I am using branches in Lyx, and I want to add a text in the beginning of a certain branch when the document is compiled. Is this possible? Also, I wanted to format a certain branch in a special way - say make some branch in a certain color.

  • I did not think this was possible but thankfully @TorbjørnT. corrected me. – scottkosty Aug 30 '17 at 7:18
  • @scottkosty I'm not able to make it work though, but I'm probably missing something. Have you tried? – Torbjørn T. Aug 30 '17 at 8:33
  • @scottkosty, I didn't understand if this is possible or not. – bobsacameno Aug 30 '17 at 11:47
  • @TorbjørnT. I haven't tried it and don't have time now to test it now. – scottkosty Aug 31 '17 at 0:06
  • 1
    @roi.holtzman If you can't get it to work, please ping me in a month and I will take a look at it then. I'm sorry for not having time now for it. If you can get it to work, please add an answer to this question. I think it is a very useful feature so others will be interested! – scottkosty Aug 31 '17 at 20:46
3

You can use LyX's layout formatting to customize specific branches (starting with LyX version 2.1.0). Below I will show how to have a branch always show its contents in green and wrapped the LaTeX in a green \textcolor command.

  1. Go to Insert > Branch > Insert New Branch. I will call it "myGreenBranch". If you change the name, change it also in step 2 below.
  2. Enter some text inside your branch inset that was created in step 1.
  3. Activate the branch inset (so we will be able to see PDF output).
  4. Go to Document > Settings.
  5. Click the "Local Layout" tab and paste the following.

    Format 60
    InsetLayout Branch:myGreenBranch
      Font
        Color green
      EndFont
      LatexName textcolor{green}
      LatexType command
      Requires color
    End
    
  6. Then click "Validate" and "OK".

The following is an example of the LyX display:

enter image description here

And here is the corresponding PDF output:

enter image description here

For more information on how to future customize branches, please read the section "Flex insets and InsetLayout" in Help > Customization.

Thanks to @TorbjørnT. for helping me realize it was possible.

Below I provide a complete example .lyx file:

#LyX 2.2 created this file. For more info see http://www.lyx.org/
\lyxformat 508
\begin_document
\begin_header
\save_transient_properties true
\origin unavailable
\textclass article
\use_default_options true
\maintain_unincluded_children false
\begin_local_layout
Format 60
InsetLayout Branch:myGreenBranch
  Font
    Color green
  EndFont
  LatexName textcolor{green}
  LatexType command
  Requires color
End
\end_local_layout
\language english
\language_package default
\inputencoding auto
\fontencoding global
\font_roman "default" "default"
\font_sans "default" "default"
\font_typewriter "default" "default"
\font_math "auto" "auto"
\font_default_family default
\use_non_tex_fonts false
\font_sc false
\font_osf false
\font_sf_scale 100 100
\font_tt_scale 100 100
\graphics default
\default_output_format default
\output_sync 1
\bibtex_command default
\index_command default
\paperfontsize default
\spacing single
\use_hyperref false
\papersize default
\use_geometry false
\use_package amsmath 1
\use_package amssymb 1
\use_package cancel 1
\use_package esint 1
\use_package mathdots 1
\use_package mathtools 1
\use_package mhchem 1
\use_package stackrel 1
\use_package stmaryrd 1
\use_package undertilde 1
\cite_engine basic
\cite_engine_type default
\biblio_style plain
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\justification true
\use_refstyle 1
\branch myGreenBranch
\selected 1
\filename_suffix 0
\color #faf0e6
\end_branch
\index Index
\shortcut idx
\color #008000
\end_index
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\paragraph_indentation default
\quotes_language english
\papercolumns 1
\papersides 1
\paperpagestyle default
\tracking_changes false
\output_changes false
\html_math_output 0
\html_css_as_file 0
\html_be_strict false
\end_header

\begin_body

\begin_layout Standard
Here is some normal text, and the following will be green: 
\begin_inset Branch myGreenBranch
status open

\begin_layout Standard
this text is green, in the LyX display and in the PDF output
\end_layout

\end_inset


\end_layout

\end_body
\end_document
  • 2
    Note that one problem of using \textcolor is that paragraph breaks are not allowed. One workaround for that is to add something like \newcommand\mybranchformat[1]{{\color{green}foobar #1}} to the preamble, and use mybranchformat for the LatexName. Note the double braces. This also allows for adding custom text (here foobar) at the start of the branch. – Torbjørn T. Jun 1 '18 at 8:18
  • @TorbjørnT. ah that is indeed an important restriction, and I didn't know about that. Thanks for adding that, and feel free to edit the answer (and any of my answers in the future) if you think it should be in there. – scottkosty Jun 1 '18 at 15:47
  • @scottkosty do you know if I can also make the branch be contained inside a box? I mean that when I add a branch, whatever I write in it, will be inside a box. – bobsacameno Jun 18 '18 at 12:37
  • @bobsacameno I would guess it's possible. I think you would just need to experiment with the LaTeX. Instead of textcolor, try e.g. fbox or whichever command it is that produces the box you want. – scottkosty Jun 18 '18 at 16:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.