private void setOutputFormat(
     RmdFrontMatter frontMatter, String format, final CommandWithArg<String> onCompleted) {
   // If the format list doesn't already contain the given format, add it
   // to the list and transfer any applicable options
   if (!JsArrayUtil.jsArrayStringContains(frontMatter.getFormatList(), format)) {
     RmdTemplate template = getTemplateForFormat(format);
     RmdFrontMatterOutputOptions opts = RmdFrontMatterOutputOptions.create();
     if (template != null) {
       opts = transferOptions(frontMatter, template, format);
     }
     frontMatter.setOutputOption(format, opts);
   }
   frontMatterToYAML(frontMatter, format, onCompleted);
 }
  private RmdFrontMatterOutputOptions transferOptions(
      RmdFrontMatter frontMatter, RmdTemplate template, String format) {
    RmdFrontMatterOutputOptions result = RmdFrontMatterOutputOptions.create();

    // loop over each option applicable to the new format; if it's
    // transferable, try to find it in one of the other formats
    JsArrayString options = template.getFormat(format).getOptions();
    for (int i = 0; i < options.length(); i++) {
      String optionName = options.get(i);
      RmdTemplateFormatOption option = template.getOption(optionName);
      if (!option.isTransferable()) continue;

      // option is transferable, is it present in another front matter entry?
      JsArrayString formats = frontMatter.getFormatList();
      for (int j = 0; j < formats.length(); j++) {
        RmdFrontMatterOutputOptions outOptions = frontMatter.getOutputOption(formats.get(j));
        if (outOptions == null) continue;
        String val = outOptions.getOptionValue(optionName);
        if (val != null) result.setOptionValue(option, val);
      }
    }

    return result;
  }