HumanReadableLogsHints.jsx 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. import PropTypes from 'prop-types'
  2. import {
  3. packageSuggestionsForCommands,
  4. packageSuggestionsForEnvironments,
  5. } from './HumanReadableLogsPackageSuggestions'
  6. import getMeta from '@/utils/meta'
  7. function WikiLink({ url, children }) {
  8. if (getMeta('ol-wikiEnabled')) {
  9. return (
  10. <a href={url} target="_blank" rel="noopener">
  11. {children}
  12. </a>
  13. )
  14. } else {
  15. return <>{children}</>
  16. }
  17. }
  18. WikiLink.propTypes = {
  19. url: PropTypes.string.isRequired,
  20. children: PropTypes.node.isRequired,
  21. }
  22. const hints = {
  23. hint_misplaced_alignment_tab_character: {
  24. extraInfoURL:
  25. 'https://www.overleaf.com/learn/Errors/Misplaced_alignment_tab_character_%26',
  26. formattedContent: () => (
  27. <>
  28. You have placed an alignment tab character '&' in the wrong place. If
  29. you want to align something, you must write it inside an align
  30. environment such as \begin
  31. {'{align}'} … \end
  32. {'{align}'}, \begin
  33. {'{tabular}'} … \end
  34. {'{tabular}'}, etc. If you want to write an ampersand '&' in text, you
  35. must write \& instead.
  36. </>
  37. ),
  38. },
  39. hint_extra_alignment_tab_has_been_changed: {
  40. extraInfoURL:
  41. 'https://www.overleaf.com/learn/Errors/Extra_alignment_tab_has_been_changed_to_%5Ccr',
  42. formattedContent: () => (
  43. <>
  44. You have written too many alignment tabs in a table, causing one of them
  45. to be turned into a line break. Make sure you have specified the correct
  46. number of columns in your{' '}
  47. <WikiLink url="https://www.overleaf.com/learn/Tables">table</WikiLink>.
  48. </>
  49. ),
  50. },
  51. hint_display_math_should_end_with: {
  52. extraInfoURL:
  53. 'https://www.overleaf.com/learn/Errors/Display_math_should_end_with_$$',
  54. formattedContent: () => (
  55. <>
  56. You have forgotten a $ sign at the end of 'display math' mode. When
  57. writing in display math mode, you must always math write inside $$ … $$.
  58. Check that the number of $s match around each math expression.
  59. </>
  60. ),
  61. },
  62. hint_missing_inserted: {
  63. extraInfoURL: 'https://www.overleaf.com/learn/Errors/Missing_$_inserted',
  64. formattedContent: () => (
  65. <>
  66. <p>
  67. You need to enclose all mathematical expressions and symbols with
  68. special markers. These special markers create a ‘math mode’.
  69. </p>
  70. <p>
  71. Use <code>$...$</code> for inline math mode, and <code>\[...\]</code>
  72. or one of the mathematical environments (e.g. equation) for display
  73. math mode.
  74. </p>
  75. <p>
  76. This applies to symbols such as subscripts ( <code>_</code> ),
  77. integrals ( <code>\int</code> ), Greek letters ( <code>\alpha</code>,{' '}
  78. <code>\beta</code>, <code>\delta</code> ) and modifiers{' '}
  79. <code>{'(\\vec{x}'}</code>, <code>{'\\tilde{x}'})</code>.
  80. </p>
  81. </>
  82. ),
  83. },
  84. hint_reference_undefined: {
  85. extraInfoURL:
  86. 'https://www.overleaf.com/learn/Errors/There_were_undefined_references',
  87. formattedContent: () => (
  88. <>
  89. You have referenced something which has not yet been labelled. If you
  90. have labelled it already, make sure that what is written inside \ref
  91. {'{...}'} is the same as what is written inside \label
  92. {'{...}'}.
  93. </>
  94. ),
  95. },
  96. hint_there_were_undefined_references: {
  97. extraInfoURL:
  98. 'https://www.overleaf.com/learn/Errors/There_were_undefined_references',
  99. formattedContent: () => (
  100. <>
  101. You have referenced something which has not yet been labelled. If you
  102. have labelled it already, make sure that what is written inside \ref
  103. {'{...}'} is the same as what is written inside \label
  104. {'{...}'}.
  105. </>
  106. ),
  107. },
  108. hint_citation_on_page_undefined_on_input_line: {
  109. extraInfoURL:
  110. 'https://www.overleaf.com/learn/Errors/Citation_XXX_on_page_XXX_undefined_on_input_line_XXX',
  111. formattedContent: () => (
  112. <>
  113. You have cited something which is not included in your bibliography.
  114. Make sure that the citation (\cite
  115. {'{...}'}) has a corresponding key in your bibliography, and that both
  116. are spelled the same way.
  117. </>
  118. ),
  119. },
  120. hint_label_multiply_defined_labels: {
  121. extraInfoURL:
  122. 'https://www.overleaf.com/learn/Errors/There_were_multiply-defined_labels',
  123. formattedContent: () => (
  124. <>
  125. You have used the same label more than once. Check that each \label
  126. {'{...}'} labels only one item.
  127. </>
  128. ),
  129. },
  130. hint_float_specifier_changed: {
  131. extraInfoURL:
  132. 'https://www.overleaf.com/learn/Errors/%60!h%27_float_specifier_changed_to_%60!ht%27',
  133. formattedContent: () => (
  134. <>
  135. The float specifier 'h' is too strict of a demand for LaTeX to place
  136. your float in a nice way here. Try relaxing it by using 'ht', or even
  137. 'htbp' if necessary. If you want to try keep the float here anyway,
  138. check out the{' '}
  139. <WikiLink url="https://www.overleaf.com/learn/Positioning_of_Figures">
  140. float package
  141. </WikiLink>
  142. .
  143. </>
  144. ),
  145. },
  146. hint_no_positions_in_optional_float_specifier: {
  147. extraInfoURL:
  148. 'https://www.overleaf.com/learn/Errors/No_positions_in_optional_float_specifier',
  149. formattedContent: () => (
  150. <>
  151. You have forgotten to include a float specifier, which tells LaTeX where
  152. to position your figure. To fix this, either insert a float specifier
  153. inside the square brackets (e.g. \begin
  154. {'{figure}'}
  155. [h]), or remove the square brackets (e.g. \begin
  156. {'{figure}'}
  157. ). Find out more about float specifiers{' '}
  158. <WikiLink url="https://www.overleaf.com/learn/Positioning_of_Figures">
  159. here
  160. </WikiLink>
  161. .
  162. </>
  163. ),
  164. },
  165. hint_undefined_control_sequence: {
  166. formattedContent: details => {
  167. if (details?.length && packageSuggestionsForCommands.has(details[0])) {
  168. const command = details[0]
  169. const suggestion = packageSuggestionsForCommands.get(command)
  170. return (
  171. <>
  172. <p>
  173. We think you’ve got a missing package! The <code>{command}</code>{' '}
  174. command won't work unless you include
  175. <code>{suggestion.command}</code> in your{' '}
  176. <WikiLink url="https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes#The_preamble_of_a_document">
  177. document preamble
  178. </WikiLink>
  179. .{' '}
  180. <WikiLink url="https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes#Finding_and_using_LaTeX_packages">
  181. Learn more about packages
  182. </WikiLink>
  183. .
  184. </p>
  185. </>
  186. )
  187. }
  188. return (
  189. <>
  190. The compiler is having trouble understanding a command you have used.
  191. Check that the command is spelled correctly. If the command is part of
  192. a package, make sure you have included the package in your preamble
  193. using <code>\usepackage</code>
  194. {'{...}'}.
  195. <div className="log-entry-content-link">
  196. <a
  197. href="https://www.overleaf.com/learn/Errors/Undefined_control_sequence"
  198. target="_blank"
  199. rel="noopener"
  200. >
  201. Learn more
  202. </a>
  203. </div>
  204. </>
  205. )
  206. },
  207. },
  208. hint_undefined_environment: {
  209. formattedContent: details => {
  210. if (
  211. details?.length &&
  212. packageSuggestionsForEnvironments.has(details[0])
  213. ) {
  214. const environment = details[0]
  215. const suggestion = packageSuggestionsForEnvironments.get(environment)
  216. return (
  217. <>
  218. <p>
  219. We think you’ve got a missing package! The{' '}
  220. <code>{environment}</code> environment won't work unless you
  221. include <code>{suggestion.command}</code> in your{' '}
  222. <WikiLink url="https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes#The_preamble_of_a_document">
  223. document preamble
  224. </WikiLink>
  225. .{' '}
  226. <WikiLink url="https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes#Finding_and_using_LaTeX_packages">
  227. Learn more about packages
  228. </WikiLink>
  229. .
  230. </p>
  231. </>
  232. )
  233. }
  234. return (
  235. <>
  236. You have created an environment (using \begin
  237. {'{…}'} and \end
  238. {'{…}'} commands) which is not recognized. Make sure you have included
  239. the required package for that environment in your preamble, and that
  240. the environment is spelled correctly.
  241. <div className="log-entry-content-link">
  242. <a
  243. href="https://www.overleaf.com/learn/Errors%2FLaTeX%20Error%3A%20Environment%20XXX%20undefined"
  244. target="_blank"
  245. rel="noopener"
  246. >
  247. Learn more
  248. </a>
  249. </div>
  250. </>
  251. )
  252. },
  253. },
  254. hint_file_not_found: {
  255. extraInfoURL:
  256. 'https://www.overleaf.com/learn/Errors/File_XXX_not_found_on_input_line_XXX',
  257. formattedContent: () => (
  258. <>
  259. The compiler cannot find the file you want to include. Make sure that
  260. you have{' '}
  261. <WikiLink url="https://www.overleaf.com/learn/how-to/Including_images_on_Overleaf">
  262. uploaded the file
  263. </WikiLink>{' '}
  264. and{' '}
  265. <WikiLink url="https://www.overleaf.com/learn/Errors/File_XXX_not_found_on_input_line_XXX.">
  266. specified the file location correctly
  267. </WikiLink>
  268. .
  269. </>
  270. ),
  271. },
  272. hint_unknown_graphics_extension: {
  273. extraInfoURL:
  274. 'https://www.overleaf.com/learn/Errors/LaTeX_Error:_Unknown_graphics_extension:_.XXX',
  275. formattedContent: () => (
  276. <>
  277. The compiler does not recognise the file type of one of your images.
  278. Make sure you are using a{' '}
  279. <WikiLink url="https://www.overleaf.com/learn/Errors/LaTeX_Error:_Unknown_graphics_extension:_.gif.">
  280. supported image format
  281. </WikiLink>{' '}
  282. for your choice of compiler, and check that there are no periods (.) in
  283. the name of your image.
  284. </>
  285. ),
  286. },
  287. hint_unknown_float_option_h: {
  288. extraInfoURL:
  289. 'https://www.overleaf.com/learn/Errors/LaTeX_Error:_Unknown_float_option_%60H%27',
  290. formattedContent: () => (
  291. <>
  292. The compiler isn't recognizing the float option 'H'. Include \usepackage
  293. {'{float}'} in your preamble to fix this.
  294. </>
  295. ),
  296. },
  297. hint_unknown_float_option_q: {
  298. extraInfoURL:
  299. 'https://www.overleaf.com/learn/Errors/LaTeX_Error:_Unknown_float_option_%60q%27',
  300. formattedContent: () => (
  301. <>
  302. You have used a float specifier which the compiler does not understand.
  303. You can learn more about the different float options available for
  304. placing figures{' '}
  305. <WikiLink url="https://www.overleaf.com/learn/Positioning_of_Figures">
  306. here
  307. </WikiLink>{' '}
  308. .
  309. </>
  310. ),
  311. },
  312. hint_math_allowed_only_in_math_mode: {
  313. extraInfoURL:
  314. 'https://www.overleaf.com/learn/Errors/LaTeX_Error:_%5Cmathrm_allowed_only_in_math_mode',
  315. formattedContent: () => (
  316. <>
  317. You have used a font command which is only available in math mode. To
  318. use this command, you must be in maths mode (E.g. $ … $ or \begin
  319. {'{math}'} … \end
  320. {'{math}'}
  321. ). If you want to use it outside of math mode, use the text version
  322. instead: \textrm, \textit, etc.
  323. </>
  324. ),
  325. },
  326. hint_mismatched_environment: {
  327. formattedContent: () => (
  328. <>
  329. You have used \begin
  330. {'{...}'} without a corresponding \end
  331. {'{...}'}.
  332. </>
  333. ),
  334. },
  335. hint_mismatched_brackets: {
  336. formattedContent: () => (
  337. <>You have used an open bracket without a corresponding close bracket.</>
  338. ),
  339. },
  340. hint_can_be_used_only_in_preamble: {
  341. extraInfoURL:
  342. 'https://www.overleaf.com/learn/Errors/LaTeX_Error:_Can_be_used_only_in_preamble',
  343. formattedContent: () => (
  344. <>
  345. You have used a command in the main body of your document which should
  346. be used in the preamble. Make sure that \documentclass[…]
  347. {'{…}'} and all \usepackage
  348. {'{…}'} commands are written before \begin
  349. {'{document}'}.
  350. </>
  351. ),
  352. },
  353. hint_missing_right_inserted: {
  354. extraInfoURL:
  355. 'https://www.overleaf.com/learn/Errors/Missing_%5Cright_insertede',
  356. formattedContent: () => (
  357. <>
  358. You have started an expression with a \left command, but have not
  359. included a corresponding \right command. Make sure that your \left and
  360. \right commands balance everywhere, or else try using \Biggl and \Biggr
  361. commands instead as shown{' '}
  362. <WikiLink url="https://www.overleaf.com/learn/Errors/Missing_%5Cright_inserted">
  363. here
  364. </WikiLink>
  365. .
  366. </>
  367. ),
  368. },
  369. hint_double_superscript: {
  370. extraInfoURL: 'https://www.overleaf.com/learn/Errors/Double_superscript',
  371. formattedContent: () => (
  372. <>
  373. You have written a double superscript incorrectly as a^b^c, or else you
  374. have written a prime with a superscript. Remember to include {'{and}'}{' '}
  375. when using multiple superscripts. Try a^
  376. {'{b ^ c}'} instead.
  377. </>
  378. ),
  379. },
  380. hint_double_subscript: {
  381. extraInfoURL: 'https://www.overleaf.com/learn/Errors/Double_subscript',
  382. formattedContent: () => (
  383. <>
  384. You have written a double subscript incorrectly as a_b_c. Remember to
  385. include {'{and}'} when using multiple subscripts. Try a_
  386. {'{b_c}'} instead.
  387. </>
  388. ),
  389. },
  390. hint_no_author_given: {
  391. extraInfoURL: 'https://www.overleaf.com/learn/Errors/No_%5Cauthor_given',
  392. formattedContent: () => (
  393. <>
  394. You have used the \maketitle command, but have not specified any
  395. \author. To fix this, include an author in your preamble using the
  396. \author
  397. {'{…}'} command.
  398. </>
  399. ),
  400. },
  401. hint_somethings_wrong_perhaps_a_missing_item: {
  402. extraInfoURL:
  403. 'https://www.overleaf.com/learn/Errors/LaTeX_Error:_Something%27s_wrong--perhaps_a_missing_%5Citem',
  404. formattedContent: () => (
  405. <>
  406. There are no entries found in a list you have created. Make sure you
  407. label list entries using the \item command, and that you have not used a
  408. list inside a table.
  409. </>
  410. ),
  411. },
  412. hint_misplaced_noalign: {
  413. extraInfoURL: 'https://www.overleaf.com/learn/Errors/Misplaced_%5Cnoalign',
  414. formattedContent: () => (
  415. <>
  416. You have used a \hline command in the wrong place, probably outside a
  417. table. If the \hline command is written inside a table, try including \\
  418. before it.
  419. </>
  420. ),
  421. },
  422. hint_no_line_here_to_end: {
  423. extraInfoURL:
  424. 'https://www.overleaf.com/learn/Errors/LaTeX_Error:_There%27s_no_line_here_to_end',
  425. formattedContent: () => (
  426. <>
  427. You have used a \\ or \newline command where LaTeX was not expecting
  428. one. Make sure that you only use line breaks after blocks of text, and
  429. be careful using linebreaks inside lists and other environments.
  430. </>
  431. ),
  432. },
  433. hint_verb_ended_by_end_of_line: {
  434. extraInfoURL:
  435. 'https://www.overleaf.com/learn/Errors/LaTeX_Error:_%5Cverb_ended_by_end_of_line',
  436. formattedContent: () => (
  437. <>
  438. You have used a \verb command incorrectly. Try replacling the \verb
  439. command with \begin
  440. {'{verbatim}'}
  441. …\end
  442. {'{verbatim}'}
  443. .\
  444. </>
  445. ),
  446. },
  447. hint_illegal_unit_of_measure_pt_inserted: {
  448. extraInfoURL:
  449. 'https://www.overleaf.com/learn/Errors%2FIllegal%20unit%20of%20measure%20(pt%20inserted)',
  450. formattedContent: () => (
  451. <>
  452. You have written a length, but have not specified the appropriate units
  453. (pt, mm, cm etc.). If you have not written a length, check that you have
  454. not witten a linebreak \\ followed by square brackets […] anywhere.
  455. </>
  456. ),
  457. },
  458. hint_extra_right: {
  459. extraInfoURL: 'https://www.overleaf.com/learn/Errors/Extra_%5Cright',
  460. formattedContent: () => (
  461. <>
  462. You have written a \right command without a corresponding \left command.
  463. Check that all \left and \right commands balance everywhere.
  464. </>
  465. ),
  466. },
  467. hint_missing_begin_document_: {
  468. extraInfoURL:
  469. 'https://www.overleaf.com/learn/Errors%2FLaTeX%20Error%3A%20Missing%20%5Cbegin%20document',
  470. formattedContent: () => (
  471. <>
  472. No \begin
  473. {'{document}'} command was found. Make sure you have included \begin
  474. {'{document}'} in your preamble, and that your main document is set
  475. correctly.
  476. </>
  477. ),
  478. },
  479. hint_mismatched_environment2: {
  480. formattedContent: () => (
  481. <>
  482. You have used \begin
  483. {'{}'} without a corresponding \end
  484. {'{}'}.
  485. </>
  486. ),
  487. },
  488. hint_mismatched_environment3: {
  489. formattedContent: () => (
  490. <>
  491. You have used \begin
  492. {'{}'} without a corresponding \end
  493. {'{}'}.
  494. </>
  495. ),
  496. },
  497. hint_mismatched_environment4: {
  498. formattedContent: () => (
  499. <>
  500. You have used \begin
  501. {'{}'} without a corresponding \end
  502. {'{}'}.
  503. </>
  504. ),
  505. },
  506. }
  507. if (!getMeta('ol-wikiEnabled')) {
  508. Object.keys(hints).forEach(ruleId => {
  509. hints[ruleId].extraInfoURL = null
  510. })
  511. }
  512. export default hints